Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 951
forgottofly Avatar asked Jun 16 '15 10:06

forgottofly


3 Answers

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>
like image 95
Blackhole Avatar answered Nov 07 '22 12:11

Blackhole


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>
like image 1
Michael Avatar answered Nov 07 '22 12:11

Michael


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.

like image 1
Babajide Fowotade Avatar answered Nov 07 '22 13:11

Babajide Fowotade