Thursday, October 23, 2014

ng-readonly : Token '-100' is an unexpected token at column 10 of the expression

Token '-100' is an unexpected token at column 10 of the expression [user.Id!=='-100'] starting at ['-100'
 
 
ng-readonly="user.Id!=='-100'"
 
The issue disappears if the code changes to
 
    ng-readonly="user.Id!='-100'"
 Or ng-readonly="user.Id!==-100"

The reason?

ng-readonly or ng-show takes an "AngularJS statement." This type of statement only has an == operator, but this operator behaves like ===. It's a bit confusing.

Type coercion means that when the operands of an operator are different types, one of them will be converted to an "equivalent" value of the other operand's type. For instance, if you do:
boolean == integer
the boolean operand will be converted to an integer: false becomes 0true becomes 1. Then the two values are compared.
However, if you use the non-converting comparison operator ===, no such conversion occurs. When the operands are of different types, this operator returns false, and only compares the values when they're of the same type.

No comments:

Post a Comment