Syntax error with ng-show: "token 'false' is at column {2} of the expression [{3}] starting at [{4}]"

2.1k views Asked by At

I'm using ng-show as shown below:

<data-ng-show={{entity.primary}}===true>

The value of entity.primary can be either true or false. I am getting the following error in the console:

Syntax Error: Token 'false' is at column {2} of the expression [{3}] starting at [{4}].

How can this error be fixed?

3

There are 3 answers

0
Blackhole On BEST ANSWER

Sadly, your code is a concentrate of errors:

  1. The ngShow directive can only be used as an attribute, and not as an element, as shown by the documentation and the code.
  2. The ngShow directive expects an "expression", which is (by and large) standard JavaScript code: you don't need additional curly brackets.
  3. Since you're using an equal sign = in your attribute, quotes are mandatory around its value, as explained by this W3C note.

Therefore, the correct code is:

<div data-ng-show="entity.primary === true"></div>
0
Michael On

ng-show evaluates an expression. you don't need braces.

try this:

<data-ng-show="entity.primary"></div>

or this:

<data-ng-show="entity.primary === true"></div>
0
Babajide Fowotade On

You should add expressions inside the curly braces but not for ng-show <data-ng-show="entity.primary === true"></div>.

However ng-show evaluates to either true or false depending on it's set value, so you should just do this <data-ng-show="entity.primary"></div>

And if you need to display the values, you could just add this somewhere

<div>{{entity.primary}}</div> => returns true or false or whatever value assigned to it.