加载 Angular 应用程序后,我需要一些模板可以离线使用。
像这样的东西是理想的:
$routeProvider
.when('/p1', {
controller: controller1,
templateUrl: 'Template1.html',
preload: true
})
最佳答案
这是对 @gargc 答案的补充。
如果你不想使用脚本标签来指定你的模板,并且想从文件中加载模板,你可以这样做:
myApp.run(function ($templateCache, $http) {
$http.get('Template1.html', { cache: $templateCache });
});
myApp.config(function ($locationProvider, $routeProvider) {
$routeProvider.when('/p1', { templateUrl: 'Template1.html' })
});
关于angularjs - 使用 AngularJS 路由时有没有办法预加载模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18714690/