Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template inexplicably not loaded from $templateCache #50

Open
amaschas opened this issue Aug 22, 2016 · 2 comments
Open

Template inexplicably not loaded from $templateCache #50

amaschas opened this issue Aug 22, 2016 · 2 comments

Comments

@amaschas
Copy link

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.

@alex87
Copy link

alex87 commented Aug 31, 2016

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!

@PizzaPete
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants