I have the folowing attribute on a div: ng-show="state.name === 'index'"
. I've also tried ng-show='state.name === "index"
, but I keep getting the following error:
Syntax Error: Token '"index"' is an unexpected token at column 16 of the expression [state.name === "index"] starting at ["index"].
Why?
ng-show
takes an "AngularJS statement." This type of statement only has an ==
operator, but this operator behaves like ===
. It's a bit confusing, but handy in that you cannot shoot yourself in the foot with weird type coercion.
I found the problem. Instead of "state.name==='index'"
, I should have written "state.name=='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(state.name == 'o'){doFoo();}">o</span>