4

Template cache fails for me for some reason, when I do this:

angular.module('myApp').run([
    '$templateCache', function ($templateCache) {
        $templateCache.put('test.html', 'content');
    }
]);

and then when using routeProvider

$routeProvider.when("/my/url", {
              templateUrl: 'test.html'
          })

However, if I change my key from "test.html" to just "test", it works. For some reason, it fails soon as I add the file extension to the key.

user648931
  • 503
  • 5
  • 18
  • Define *"fails"*. Perhaps you have another template named `test.html`. Try something unique, like `test1234.html` – Phil Feb 09 '17 at 23:50
  • By fails, I mean it doesn't pull the template from the cache, and goes against the server. I tried `test1234.html` and got the same result. – user648931 Feb 09 '17 at 23:54
  • Ah, so you can see a network request being made for `test.html`? Any chance you can try to replicate the problem in a Plunker example? Do you have any customisation / configuration of `$templateCache` or `$cacheFactory`? – Phil Feb 09 '17 at 23:56
  • Looking in to other instances like this, I'm seeing suggestions to populate the `$templateCache` in a separate module (eg `'myApp.templates'`) and make it a dependency of your main module (`'myApp'`). Give that a try – Phil Feb 10 '17 at 00:05
  • 1
    I completely forgot I had an interceptor adding a query param to my request (for cache busting), which I overlooked when looking at the network call. No issues here (apart from me missing a simple thing :/ ). Thanks nonetheless for your suggestions! – user648931 Feb 10 '17 at 00:09

0 Answers0