简体   繁体   English

JavaScript AngularJS 错误“SyntaxError: Unexpected token }”

[英]JavaScript AngularJS error "SyntaxError: Unexpected token }"

I have an SPA that needs to support any language.我有一个需要支持任何语言的 SPA。 Upon loading, it deploys all the labels in a default language.加载后,它会以默认语言部署所有标签。 Within the HTML, these are included as:在 HTML 中,这些包括:

:
<label ...>{{Labels.Username}}</label>
:
<label ...>{{Labels.Password}}</label>
:

(This is just an example, not the actual HTML). (这只是一个例子,不是实际的 HTML)。

Now, upon initial loading, all goes OK.现在,在初始加载时,一切正常。 When I attempt to change language (even to the initial default language) I get the following error:当我尝试更改语言(甚至更改为初始默认语言)时,出现以下错误:

SyntaxError: Unexpected token }
at Object.parse (native)
at pc (http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:14:486)
at Xb (http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:80:157)
at http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:81:70
at n (http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:7:302)
at $c (http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:81:52)
at c (http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:82:235)
at http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:118:182
at m.$eval (http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:132:221)
at m.$digest (http://127.0.0.1:55659/Public_Libs/Angular/angular.min.js:129:233)(anonymous function) @ angular.js:12116(anonymous function) @ angular.js:8976(anonymous function) @ angular.js:14355m.$eval @ angular.js:15574m.$digest @ angular.js:15385m.$apply @ angular.js:15679l @ angular.js:10166J @ angular.js:10338w.onload @ angular.js:10279

I attempted to debug this by setting breakpoints into my JavaScript code at every relevant location, but (as suggested by the error) the issue appears to be within the Angular code.我试图通过在每个相关位置在我的 JavaScript 代码中设置断点来调试它,但是(如错误所建议的那样)问题似乎出在 Angular 代码中。 I need to find our what triggers this.我需要找到我们是什么触发了这个。

Found the issue.发现问题。 It had to do with the fact that, under certain conditions, the JSON that was received (ie its string representation) from the remote server was wrongly formatted.这与这样一个事实有关,在某些情况下,从远程服务器接收到的 JSON(即它的字符串表示)格式错误。

It took me some time to find this, and it looks to me reasonable to assume that I would reach this much faster had AngularJS provided more clear description of the error (this particular as well as others).我花了一些时间才找到这个,而且在我看来,如果 AngularJS 提供了更清晰的错误描述(这个特殊的以及其他的),我会更快地达到这个目标。

Thanks to those that sent comments and recommendations.感谢那些发送评论和建议的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM