2

我正在VS2013中使用Angular JS項目(angular version v1.4.4)創建一個MVC5。我正沿着編碼和一切都很好,然後突然我開始在啓動此錯誤:AngularJS v1.4.4 IE10預期標識符錯誤

JavaScript critical error at line 5395, column 34 in http://localhost:63937/Scripts/angular.js \n\nSCRIPT1010: Expected identifier

我只得到IE10中的這個錯誤,它工作正常在Chrome。

我的引用是一個佈局文件,看起來像這樣:

<link href="~/Content/bootstrap.css" rel="stylesheet" /> 
<link href="~/Content/Site.css" rel="stylesheet" /> 
<script src="~/Scripts/jquery-1.10.2.js"></script> 
<script src="~/Scripts/angular.js"></script> 
<script src="~/Scripts/bootstrap.js"></script> 
<script src="~/Scripts/angular-route.js"></script> 

HTML網頁中包含的參考App.js文件。我可以發佈一些代碼,但它似乎沒有擊中App.JS文件。任何人遇到這個問題或有任何建議,我應該從哪裏開始尋找問題?據我所知,我將代碼恢復到它在IE10中工作的地步,但它仍然不會運行。

以下是angular.js文件中包含錯誤行號的特定函數。具體的行是在'catch'函數中的回報聲明:

getPromise: function() { 
    if (!this.defer) { 
    this.defer = $q.defer(); 
    } 
    return this.defer.promise; 
}, 
then: function(f1,f2) { 
    return this.getPromise().then(f1,f2); 
}, 
'catch': function(f1) { 
    return this.getPromise().catch(f1); 
}, 
'finally': function(f1) { 
    return this.getPromise().finally(f1); 
} 

任何幫助將不勝感激。

+0

我會建議你使用的版本1.3.18' '因爲這是最後一個穩定版本。截至目前,AngularJS團隊還沒有發佈穩定的'1.4.x'版本。 – yvesmancera

+0

@yvesmancera,你確定嗎?在Visual Studio 2013 NuGet Manager中,它被列爲穩定版本 – Snicklefritz

+0

我的不好,看起來你是對的,1.4.4是穩定版本。 – yvesmancera

回答

2

它看起來是這樣的,最近特別是在v1.4.4根據changelog介紹:

$animateCss: make sure that skipBlocking avoids the pre-emptive transition-delay styling

要展開多一點說的投擲錯誤設置一些上下文行:

var $CoreAnimateCssProvider = function() { 
    this.$get = ['$$rAF', '$q', function($$rAF, $q) { 

    var RAFPromise = function() {}; 
    RAFPromise.prototype = { 
     done: function(cancel) { 
     this.defer && this.defer[cancel === true ? 'reject' : 'resolve'](); 
     }, 
     end: function() { 
     this.done(); 
     }, 
     cancel: function() { 
     this.done(true); 
     }, 
     getPromise: function() { 
     if (!this.defer) { 
      this.defer = $q.defer(); 
     } 
     return this.defer.promise; 
     }, 
     then: function(f1,f2) { 
     return this.getPromise().then(f1,f2); 
     }, 
     'catch': function(f1) { 
     return this.getPromise().catch(f1); 
     }, 
     'finally': function(f1) { 
     return this.getPromise().finally(f1); 
     } 
    }; 
//... more code 

$CoreAnimateCssProvider沒有包含在1.4.3中,所以它絕對是新的。

我的建議是,您現在嘗試版本1.4.3,直到修復此錯誤。

+0

我嘗試1.4.3和angular.min.js只是拋出一個新的錯誤:SCRIPT5007:預期的對象文件:angular.min.js,行:7,列:238.這是在IE 11.0.9600。 .Catch還嘗試使用另一個錯誤1.6.1。 – monty

0

我在IE 11.0.9600有類似的問題。我嘗試1.4.3和angular.min.js只是把一個新的錯誤:

SCRIPT5007: Object expected 
File: angular.min.js, Line: 7, Column: 238. 

也試過1.6.1,其在JS不同的「.catch」拋出另一個錯誤。

但是,這個錯誤也可能是由於doctype被搞砸和IE試圖解析舊模式中的東西造成的。要修復,請添加到您的網絡。配置文件:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.webServer> 
    <httpProtocol> 
     <customHeaders> 
     <clear /> 
     <add name="X-UA-Compatible" value="IE=10" /> 
     </customHeaders> 
    </httpProtocol> 
    </system.webServer> 
</configuration> 

或者,在你的主人佈局頁地址:

<meta http-equiv="X-UA-Compatible" content="IE=11" /> 

而且還要檢查你的doctype聲明是簡單的:

<!doctype html> 

在一個側面說明,也有在IE瀏覽器中使用angularjs的其他幾個常見問題(甚至是最新版本),這些問題歸結爲:

  1. 納克式標籤而不是風格= 「{{someCss}}」
  2. NG-ATTR型標記而不是類型=在按鈕 「{{someExpression}}」,而不是
  3. NG-ATTR值標籤值= 「{{someExpression}}」
  4. NG-ATTR佔位符標記而不是佔位符= 「{{someExpression}}」

IE compatibility with angular