有没有办法使AngularJS负载分支在开始,而不是在需要时?
发布时间:2020-12-17 09:26:24 所属栏目:安全 来源:网络整理
导读:我有一个这样的路由设置: var myApp = angular.module('myApp',[]). config(['$routeProvider',function ($routeProvider) { $routeProvider. when('/landing',{ templateUrl: '/landing-partial',controller: landingController }). when('/:wkspId/query'
我有一个这样的路由设置:
var myApp = angular.module('myApp',[]). config(['$routeProvider',function ($routeProvider) { $routeProvider. when('/landing',{ templateUrl: '/landing-partial',controller: landingController }). when('/:wkspId/query',{ templateUrl: '/query-partial',controller: queryController }). otherwise({ redirectTo: '/landing' }); }]); 我想要能够使angularjs在开始下载两个partials而不是当请求时。 可能吗?
是的,至少有两个解决方案:
>使用脚本指令(http://docs.angularjs.org/api/ng.directive:script)将您的部分放在最初加载的HTML中 如果你想使用方法(2)填写$ templateCache,你可以这样做: $templateCache.put('second.html','<b>Second</b> template'); 当然模板内容可能来自$ http调用: $http.get('third.html',{cache:$templateCache}); 这里是plunker那些技术:http://plnkr.co/edit/J6Y2dc?p=preview (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |