简体   繁体   中英

JavaScript AngularJS error "SyntaxError: Unexpected token }"

I have an SPA that needs to support any language. Upon loading, it deploys all the labels in a default language. Within the HTML, these are included as:

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

(This is just an example, not the actual 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. 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.

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).

Thanks to those that sent comments and recommendations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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