bigblind bigblind - 1 year ago 71
AngularJS Question

Why is AngularJS complaining about an unexpected token in an expression when I try to use a string?

I have the folowing attribute on a div:

ng-show=" === 'index'"
. I've also tried
ng-show=' === "index"
, but I keep getting the following error:

Syntax Error: Token '
' is an unexpected token at column 16 of the expression
[ === "index"]
starting at


Answer Source

I found the problem. Instead of "'index'", I should have written "'index'". pkoziowski.opensource was right, in that you can't use conditional statements, but what they mean by that, is that you can't use if statements, or any control flow statements for that matter, so you couldn't do this:

<span ng-init="if( == 'o'){doFoo();}">o</span>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download