Marcel
Marcel

Reputation: 15722

How to fix IE9 throwing SCRIPT1028 error, using AngularJS?

I use AngularJS in my single-page application. Somewhere I have defined a button like this

<button class="btn btn-success" onclick="doSeekTo({{todo.position}});doPlay();">

This button, when clicked, invokes the javascript function with the given parameter in double curly braces, as usual with AngularJS.

This all works well in IE9, but when looking at the error console, it says “Expected identifier, string or number” at the position of my curly braces.

How to get rid of this error? It makes me feel uncomfortable.

Upvotes: 1

Views: 524

Answers (3)

MI-Joe
MI-Joe

Reputation: 11

Another option is to enclose the {{}} in single quotes such that IE interprets it as a string:

<button class="btn btn-success"> onclick="doSeekTo('{{todo.position}}');doPlay();">

Upvotes: 1

Max
Max

Reputation: 8836

In Angular, you're not supposed to use the built in onclick event, but rather Angular's ng-click event. That way you can write

ng-click="doSeekTo(todo.position);doPlay()"

Upvotes: 3

Louis Ricci
Louis Ricci

Reputation: 21086

IE9 is parsing the HTML before your angularjs code modifies it. Maybe some indirection like this would help ...

<button class="btn btn-success" paramvalue="{{todo.position}}" onclick="doSeekTo(this.paramvalue);doPlay();">

Upvotes: 1

Related Questions