Вопрос

If there any way by which I can use

 $templateCache.put("test.html", "<div>something</div>"); as
 $templateCache.put("test.html", PATH_TO_TEST.HTML);

to cache a template.

Thanks.

Это было полезно?

Решение

You might want to check out this grunt module: https://www.npmjs.org/package/grunt-angular-templates

You can use it to pre-process your templates directory and create an app module with all of your external templates loaded into the templateCache.

Other than that, I'm not sure. You could pre-load them yourself using $http and put them in the cache if it's really important to have them pre-loaded.

When you use templateUrl in a directive or ng-include, angular automatically puts the template into the cache if it's not already there, so it should only be loading the template file once via http regardless of how many times it's used. There's usually no need to interact with $templateCache yourself.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top