簡體   English   中英

角$ templateCache在Internet Explorer中不起作用

[英]Angular $templateCache Does Not Work in Internet Explorer

我在ie10中特別遇到了Angular的$ templateCache問題,但在ie11中也存在問題。 它可以在Firefox,Chrome和Safari中使用。

這是我在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"
    ...
  );
}]);

我在<head>頁面頂部包含templates.js,例如:

<script src="/js/templates.js"></script>

最后,我在路由定義中使用這些模板,這里:

angular.module('app', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
  $routeProvider
    .when('/', {
      redirectTo:'/page'
    })
    .when('/page', {
      controller: 'pageController',
      templateUrl:'/views/page.html'
    })
    .otherwise({
      redirectTo:'/'
    });
}]);

同樣,它們在Chrome,Firefox和Safari中都可以正常工作,但在IE10上卻不能。 我想提供的唯一其他信息是該應用程序不是root級別,而是http://example.com/app 但模板確實存儲在http://example.com/views中

有任何想法嗎?

編輯:這是一個實際上可以在IE中運行的JSFiddle,但是我不確定這是否是因為JSFiddle如何處理瀏覽器框架。 如果將代碼復制並粘貼到index.html中,然后在您的服務器上運行它,則它將無法在IE中使用。 http://jsfiddle.net/v9sv7jdL/2/

在這種情況下,實際上我們的IE應用程序具有特殊的邏輯。 它在請求的末尾添加了一個?ts =,這當然在templateCache中不存在。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM