有使用AngularJS路由预加载模板的方法吗?

加载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’)

相关文章

ANGULAR.JS:NG-SELECTANDNG-OPTIONSPS:其实看英文文档比看中...
AngularJS中使用Chart.js制折线图与饼图实例  Chart.js 是...
IE浏览器兼容性后续前言 继续尝试解决IE浏览器兼容性问题,...
Angular实现下拉菜单多选写这篇文章时,引用文章地址如下:h...
在AngularJS应用中集成科大讯飞语音输入功能前言 根据项目...
Angular数据更新不及时问题探讨前言 在修复控制角标正确变...