有使用AngularJS路由预加载模板的方法吗?
发布时间:2020-12-17 08:55:07 所属栏目:安全 来源:网络整理
导读:加载Angular应用程序后,我需要一些离线可用的模板。 这样的东西是理想的: $routeProvider .when('/p1',{ controller: controller1,templateUrl: 'Template1.html',preload: true }) 有一个模板缓存服务: $templateCache,可以用来在javascript模块中预加
加载Angular应用程序后,我需要一些离线可用的模板。
这样的东西是理想的: $routeProvider .when('/p1',{ controller: controller1,templateUrl: 'Template1.html',preload: true })
有一个模板缓存服务:
$templateCache,可以用来在javascript模块中预加载模板。
例如,从文档: var myApp = angular.module('myApp',[]); myApp.run(function($templateCache) { $templateCache.put('templateId.html','This is the content of the template'); }); 甚至有一个grunt任务从html文件预生成一个javascript模块:grunt-angular-templates 另一种方式,也许不太灵活,是使用内联模板,例如,在index.html中有一个类似这样的脚本标签: <script type="text/ng-template" id="templates/Template1.html">template content</script> 意味着模板可以在后面以与路由配置中的真实url相同的方式进行编址(templateUrl:’templates / Template1.html’) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |