Is there a way to preload templates when using AngularJS routing?

前端 未结 5 1648
渐次进展
渐次进展 2020-12-04 11:23

After the Angular app is loaded I need some of the templates to be available offline.

Something like this would be ideal:

$routeProvider
  .when(\'/p         


        
5条回答
  •  难免孤独
    2020-12-04 11:50

    Preloads all templates defined in module routes.

    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});
          }
        }
    })
    

提交回复
热议问题