ngtemplate-loader
ngtemplate-loader copied to clipboard
Template inexplicably not loaded from $templateCache
I've noticed this issue in two projects thus far. The loader will properly stick the template into the cache, but somehow can't retrieve it. So for instance, if this fails:
import template from './template.html';
...
templateURL: template,
...
and this fails:
templateURL: <pasted value of template var>,
but this works:
template: ['$templateCache', function ($templateCache) {
return $templateCache.get(template);
}],
In many cases, the template will properly load for some directives or components and fail for others.
Hi, I just ran into to a similar issue - some templates not being loaded despite being in the template cache.
It turned out I was requiring the template in the wrong place, so the code to put it into the template cache was not being executed until to late.
I was doing this:
module.exports = function(){
var templatePath = require('./template.tpl.html');
...
templateURL: templatePath,
...
}
And I fixed it by putting the templates require outside of the angular code.
var templatePath = require('./template.tpl.html');
module.exports = function(){
...
templateURL: templatePath,
...
}
I'm not sure if this would be the same issue as I'm using require not import but thought it might help!
We're having the same issue. Using the way @alex87 did, also fails for us:
templateUrl: require('./template.html')
Using the fix of @alex87 it works. Although it would be better to import the template directly in the component/directive declaration.