Several methods were found using $http and $route in stack responses .
I think the most attractive is
angular.module('MyApp', []) .run(function ($templateCache, $route, $http) { var url; for(var i in $route.routes) { if (url = $route.routes[i].templateUrl) { $http.get(url, {cache: $templateCache}); } } })
Thus, all the templates in the route are loaded at the first start.
EDIT: I am using a UI Router , so the thing looks a little different in the angular.run() block. Nested views are not yet processed.
angular.forEach($state.get(), function(state){ if(state.templateUrl){ $http.get(state.templateUrl, {cache: $templateCache}); } });
EDIT 2: I skipped $ templateRequest, which could be the path to the html template in the angular.run() block.
$templateRequest('views/cart/modal-confirm-continue-printing.html'); $templateRequest('views/cart/modal-confirm-trash.html');
EDIT 3: Since I am creating grunt applications, I find https://www.npmjs.com/package/grunt-angular-templates usefoul to automate this process.
source share