[英]Angular $templateCache Does Not Work in Internet Explorer
I am having an issue with Angular's $templateCache in ie10 specifically, but is also an issue in ie11. 我在ie10中特别遇到了Angular的$ templateCache问题,但在ie11中也存在问题。 It works in Firefox, Chrome and Safari. 它可以在Firefox,Chrome和Safari中使用。
Here is my template definition, in templates.js: 这是我在template.js中的模板定义:
angular.module('app').run(['$templateCache', function($templateCache) {
'use strict';
$templateCache.put('/views/page.html',
"<div class=\"page-header row\">\n" +
" <div class=\"col-xs-6\">\n" +
" <span class=\"heading title\">{{pageTitle}}</span>\n"
...
);
}]);
I include the templates.js at the top of the page in the <head>
, like: 我在<head>
页面顶部包含templates.js,例如:
<script src="/js/templates.js"></script>
And finally I consume the templates in my routes definition, here: 最后,我在路由定义中使用这些模板,这里:
angular.module('app', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/', {
redirectTo:'/page'
})
.when('/page', {
controller: 'pageController',
templateUrl:'/views/page.html'
})
.otherwise({
redirectTo:'/'
});
}]);
Again, it all works fine in Chrome, Firefox and Safari, but not IE10. 同样,它们在Chrome,Firefox和Safari中都可以正常工作,但在IE10上却不能。 The only other information I can think to provide is that the app is not at the root level, it is http://example.com/app . 我想提供的唯一其他信息是该应用程序不是root级别,而是http://example.com/app 。 but the templates are indeed stored in http://example.com/views . 但模板确实存储在http://example.com/views中 。
Any ideas? 有任何想法吗?
EDIT: Here is a JSFiddle which actually works in IE, but I'm not sure if that's because of how JSFiddle handles the browser frame. 编辑:这是一个实际上可以在IE中运行的JSFiddle,但是我不确定这是否是因为JSFiddle如何处理浏览器框架。 If you copy and paste the code into an index.html, and run it on your server, it will not work in IE. 如果将代码复制并粘贴到index.html中,然后在您的服务器上运行它,则它将无法在IE中使用。 http://jsfiddle.net/v9sv7jdL/2/ http://jsfiddle.net/v9sv7jdL/2/
In this case we actually had special logic in our app for IE. 在这种情况下,实际上我们的IE应用程序具有特殊的逻辑。 It adds a ?ts= to the end of our requests, which of course, does not exist in the templateCache. 它在请求的末尾添加了一个?ts =,这当然在templateCache中不存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.