angularjs – 从文件加载$templateCache
发布时间:2020-12-17 17:53:28 所属栏目:安全 来源:网络整理
导读:我一直无法从$templateCache加载模板. 我如何在$templateCache中放置模板: var app = angular.module('anglober',['anglober.controllers','anglober.services','anglober.directives']).run(function ($templateCache,$http) { $http.get('anglober/js/inv
我一直无法从$templateCache加载模板.
我如何在$templateCache中放置模板: var app = angular.module('anglober',['anglober.controllers','anglober.services','anglober.directives']).run(function ($templateCache,$http) { $http.get('anglober/js/invitation/invitationModal.tpl.html',{cache: $templateCache}); $http.get('anglober/js/modal/ajaxModal.tpl.html',{cache: $templateCache}); $http.get('anglober/js/ajaxLoader/ajaxLoader.tpl.html',{cache: $templateCache}); $http.get('anglober/js/modal/modalContent.tpl.html',{cache: $templateCache}); $http.get('anglober/js/modal/simpleModal.tpl.html',{cache: $templateCache}); $http.get('anglober/js/mog/topMogs.tpl.html',{cache: $templateCache}); 我如何加载它们: angular.module('anglober.directives').directive('topMogs',['$templateCache',function ($templateCache) { return { restrict : 'E',template: $templateCache.get('topMogs.tpl.html') //Tried this too // templateUrl: 'topMogs.tpl.html' }; }]); 在我的网络浏览器选项卡中,我可以看到在页面加载时加载的模板. 但是,在调用我的指令时出现以下错误: One of template or templateUrl options is required. 我究竟做错了什么 ? 谢谢 解决方法
对这个旧线程的微小补充:尽管实现目标的方法很少,但我发现对我来说最好的方法是将$templateCache逻辑添加到我的每个应用程序的指令中.这样我就可以避免使用任何外部软件包,比如grunt angular-templates,这很棒 – 但对我的应用来说有点过分.
angular.module('MyApp') .directive('MyDirective',function($templateCache) { return { restrict: 'E',template: $templateCache.get('MyTemplate'),controller: 'MyController',controllerAs: 'MyController' }; }]).run(function($templateCache,$http) { $http.get('templates/MyTemplate.html').then(function(response) { $templateCache.put('MyTemplate',response.data); }) }); 希望这可以帮助! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 免费好用稳定的天气预报WebService - Weather We
- angularjs – 如何使用App Config中初始化的Angu
- Angular.js与Bootstrap相结合实现手风琴菜单代码
- 无法在Angularjs中使用templateUrl加载模板
- twitter-bootstrap – Knockout验证和Twitter Bo
- Bootstrap入门书籍之(五)导航条、分页导航
- webservice篇:其中关于调用外界数据,读取返回数
- 在页面内动态加载AngularJS模板
- WebService大讲堂之Axis2(6):跨服务会话(Sessio
- Angular 2 Web Pack 404 Html模板URL
热点阅读