question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Template is not loaded

See original GitHub issue

I’m updating my app to use Webpack 2. While ngtable is working fine if loaded with webpack 1, I experience an issue while loading with webpack 2.

The browser console shows GET http://app.finderbox.dev/app/ng-table/pager.html 404 (Not Found). In the component loading the table I set some log output:

$templateCache.get('http://app.finderbox.dev/app/ng-table/pager.html'):  undefined
$templateCache.get('http://app.finderbox.dev/ng-table/pager.html'):  undefined
$templateCache.get('ng-table/pager.html'):  Promise {$$state: Object}

It seems to be that ngtable loads templates with a different ID. @TheLarkInn: do you think that it could be an error on the webpack side? @faceleg: is that related to your issue https://github.com/esvit/ng-table/issues/957?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

7reactions
kevinboostencommented, Feb 20, 2017

I had the same issues with some missing html templates when using ngTable with Webpack 2.2. Importing the ngTable module from the /bundles directory seems to be working properly. But this is more like a workaround for now I guess.

import { ngTableModule } from 'ng-table/bundles/ng-table';

angular.module('myapp', [
    ngTableModule.name
]);
1reaction
rmunncommented, Oct 5, 2020

I managed to get the templates loading without any manual steps, by configuring Webpack with the following in my webpack.config.js file (using Webpack 3.11.0):

    module: {
      rules: [
        // ...
        { test: /ng-table\/.*\.html$/, use: ['ngtemplate-loader?requireAngular&relativeTo=/src/browser/&prefix=ng-table/', 'html-loader'] }
      ]
    }

This also requires the ngtemplate-loader and html-loader NPM packages to be installed; once that is done, this config should work as-is for anyone else using Webpack 3.x. (For Webpack 2.x or 4.x, a similar line should work but maybe in a different part of the Webpack config file). This causes Webpack to compile the templates into my vendor.bundle.js file as follows:

/* 570 */
/***/ (function(module, exports, __webpack_require__) {

// Module
var code = "<div class=\"ng-cloak ng-table-pager\" ng-if=\"params.data.length\"> <div ng-if=\"params.settings().counts.length\" class=\"ng-table-counts btn-group pull-right\"> <button ng-repeat=\"count in params.settings().counts\" type=\"button\" ng-class=\"{'active':params.count() == count}\" ng-click=\"params.count(count)\" class=\"btn btn-default\"> <span ng-bind=\"count\"></span> </button> </div> <ul ng-if=\"pages.length\" class=\"pagination ng-table-pagination\"> <li class=\"page-item\" ng-class=\"{'disabled': !page.active && !page.current, 'active': page.current}\" ng-repeat=\"page in pages\" ng-switch=\"page.type\"> <a class=\"page-link\" ng-switch-when=\"prev\" ng-click=\"params.page(page.number)\" href=\"\">&laquo;</a> <a class=\"page-link\" ng-switch-when=\"first\" ng-click=\"params.page(page.number)\" href=\"\"><span ng-bind=\"page.number\"></span></a> <a class=\"page-link\" ng-switch-when=\"page\" ng-click=\"params.page(page.number)\" href=\"\"><span ng-bind=\"page.number\"></span></a> <a class=\"page-link\" ng-switch-when=\"more\" ng-click=\"params.page(page.number)\" href=\"\">&#8230;</a> <a class=\"page-link\" ng-switch-when=\"last\" ng-click=\"params.page(page.number)\" href=\"\"><span ng-bind=\"page.number\"></span></a> <a class=\"page-link\" ng-switch-when=\"next\" ng-click=\"params.page(page.number)\" href=\"\">&raquo;</a> </li> </ul> </div> ";
// Exports
var _module_exports = code;;
var path = 'ng-table/pager.html';
var angular = __webpack_require__(0);
angular.module('ng').run(['$templateCache', function(c) { c.put(path, _module_exports) }]);
module.exports = path;

/***/ }),

Note how the path is ng-table/pager.html. The relativeTo=/src/browser/ part of the Webpack config turns node_modules/ng_table/src/browser/pager.html into pager.html, and then prefix=ng-table/ adds the ng-table prefix to the name that ngtemplate-loader compiles it with. This results in Angular’s template cache being pre-loaded with an ng-table/pager.html template, and so when the ng-table code requests the ng-table/pager.html template, Angular finds it and displays it correctly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Template kit not loading - WordPress.org
Hey there, Just been having a play round with Royal elementor but am having a bit of trouble getting the template kits to...
Read more >
Template not loading - Stack Overflow
Angular compiles the directives as it goes over DOM. You can't have it "wait" on a directive. What you could do, is not...
Read more >
Load or unload a template or add-in program - Microsoft Support
If you quit and then restart Word, the template or add-in is not automatically reloaded. In Word 2010, 2013, or 2016, select File...
Read more >
Template Not Loading - Using Django
Hi Everyone I am building a simple blog app using Django. I have created two pages so far: index.html and posts.html. On the...
Read more >
Template not loading with get_template_part or locate_template
From your comment: (formatted for brevity). The cute thing is I debugged that TEMPLATE_MODULE_DIR . 'my-template.php' and the path in a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found