'错误:[$ parse:lexerr] Lexer错误:heroku部署上出现意外的下一个字符

Con*_*ech 30 angularjs

我用自耕农发电机写了一个角应用程序.它在开发中运行良好,但在我部署到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) 
Run Code Online (Sandbox Code Playgroud)

此描述表示当表达式出现词法错误时会发生错误.

那是什么,为什么它只出现在生产中?

pri*_*ion 32

我使用ng-click时遇到了一些错误

<a ng-click="#/search/San+Francisco">test</a>
Run Code Online (Sandbox Code Playgroud)

而不是ng-href

<a ng-href="#/search/San+Francisco">test</a>
Run Code Online (Sandbox Code Playgroud)

我希望它可能有所帮助


小智 22

如果您使用的是ng-pattern ='/ some_reg_ex /'.请保存在某个范围变量中$scope.emailPattern = '/email_regex/'


Til*_*aen 16

在我的情况下,这是由正则表达式未被封闭引起的/,即.ng-pattern="^[0-9]$"而不是ng-pattern="/^[0-9]$/".


Jam*_*ruk 15

通常,当angular期望表达式或函数时,当您提供字符串文字时会发生这种情况.字符串中的"#"会导致$parse:lexerr错误.

在我的例子中,当我应该使用表达式时,我正在将字符串文字设置为自定义指令属性.

不正确:

<my-directive my-attr="/foo#bar"></my-directive>
Run Code Online (Sandbox Code Playgroud)

正确:

<my-directive my-attr="'/foo#bar'"></my-directive>
Run Code Online (Sandbox Code Playgroud)

在此示例中,该my-attr属性已设置为自定义中的双向绑定(=)my-directive.如果设置为"@",则不会发生错误.

scope: {
  my-attr: "="
}
Run Code Online (Sandbox Code Playgroud)