2014-03-01 32 views
26

我寫了一個使用yeoman生成器的角度應用程序。它在發展的偉大工程,但在我部署到Heroku的和訪問特定頁面我得到這個錯誤:

Error: [$parse:lexerr] Lexer Error: Unexpected next character at columns 0-0 [\] in expression [\]. 
http://errors.angularjs.org/1.2.6/$parse/lexerr?p0=Unexpected%20nextharacter%20&p1=s%200-0%20%5B%5C%5D&p2=%5C 
    at http://ang-news.herokuapp.com/scripts/244c37f5.vendor.js:3:30474 
    at Zd.throwError (http://ang-news.herokuapp.com/scripts/244c37f5.vendor.js:6:14396) 
    at Zd.lex (http://ang-news.herokuapp.com/scripts/244c37f5.vendor.js:6:13696) 
    at $d.parse (http://ang-news.herokuapp.com/scripts/244c37f5.vendor.js:6:16445) 
    at http://ang-news.herokuapp.com/scripts/244c37f5.vendor.js:5:13197 
    at e.parseAs (http://ang-news.herokuapp.com/scripts/244c37f5.vendor.js:5:23401) 
    at Object.e.(anonymous function) [as parseAsResourceUrl] (http://ang-news.herokuapp.com/scripts/244c37f5.vendor.js:5:23604) 
    at http://ang-news.herokuapp.com/scripts/244c37f5.vendor.js:6:28873 
    at q (http://ang-news.herokuapp.com/scripts/244c37f5.vendor.js:4:23046) 
    at h (http://ang-news.herokuapp.com/scripts/244c37f5.vendor.js:4:19250) 

This description說,當一個表達式有一個詞法錯誤發生錯誤。

那是什麼,爲什麼它只在生產中出現?

+0

你部署的所有腳本文件到服務器? –

+0

在我的情況下,這是一個「而不是」 –

回答

32

我有一些錯誤,而我 使用NG單擊

<a ng-click="#/search/San+Francisco">test</a> 

代替NG-HREF

<a ng-href="#/search/San+Francisco">test</a> 

我希望它可以幫助

+0

我猜'href'也會做的伎倆 – luchosrock

3

@russenreaktor是正確,但更具體地說,當您使用不正確的s時會發生此錯誤yntax。對於我來說,我不小心弄丟了$字符,在角度使用,#,用於在車把:

<button class="danger" type="button" title="Remove Property Asset {{#index}}">Remove Asset</button> 

當然,固定#字符解決了我的問題:

<button class="danger" type="button" title="Remove Property Asset {{$index}}">Remove Asset</button> 
17

如果你是使用ng-pattern ='/ some_reg_ex /'。請保存它在某些範圍內變化,說$scope.emailPattern = '/email_regex/'

1

在我的情況是有一個#

壞NG-顯示:

<a ng-show='#'> 

最佳。

ng-disabled="{{surveyCtrl.user.googleEmail}}" 

條件的工作:

ng-disabled="{{surveyCtrl.user.googleEmail != ''}}" 
0

當我的模型值surveyCtrl.user.googleEmail[email protected],我使用時得到這個錯誤。

ng-click="#" 

我剛剛刪除它,錯誤消失了。

2

我有NG-點擊一個問題

8

一般而言,當在角度期望表達式或函數時提供字符串文字時會發生這種情況。字符串中的「#」會導致$parse:lexerr錯誤。

在我的情況下,當我應該使用表達式時,我將字符串文字設置爲自定義指令屬性。

不正確

<my-directive my-attr="/foo#bar"></my-directive> 

正確

<my-directive my-attr="'/foo#bar'"></my-directive> 

在這個例子中,my-attr屬性是爲在自定義my-directive雙向綁定(=)設置。如果它被設置爲「@」,則錯誤不會發生。

scope: { 
    my-attr: "=" 
} 
+1

這幫助了我很大的時間 - 謝謝你先生!+1 – NickyTheWrench

11

在這種情況下,我用正則表達式不被/封閉,即引起。 ng-pattern="^[0-9]$"而不是ng-pattern="/^[0-9]$/"

+0

考慮這種情況下,我想傳遞一個正則表達式到一個指令然後在模板中使用ng-pattern。因此,我傳遞了沒有分隔符的正則表達式,例如** pattern =「^ [abc] $」**,並且我使用* @ *作爲屬性,並且在模板中使用** ng-pattern = {{pattern}} **。我在控制檯上得到Lex錯誤信息,但是正則表達式正常工作。任何想法如何擺脫控制檯錯誤? –

1

參數作爲字符串傳遞是不是一個有效的文本字符串:的

ng-init('[aa]') 

代替

ng-init([aa]) 
+0

謝謝,Man!它幫助我+1 – rufatZZ