Question

I just want to use conditional operator in a view:

 <input type="password" ng-model="password" />
 {{ ( password == "qwerty") ? 'PASSED' : 'NOT PASSED' }}

But it throws error:

Lexer Error: Unexpected next character at columns 25-25 [?] in expression [ ( password == "qwerty") ? 'PASSED' : 'NOT PASSED' ].

I know i can solve it with controller or with something like ['true':'PASSED','false':'NOT PASSED'][(password == "qwerty")] but what is the problem with the '?'?

Fiddle: http://jsfiddle.net/cherniv/KAgrw/

Was it helpful?

Solution

You need to use angular 1.1.5+/1.2+. Which version of angular are you using?

OTHER TIPS

If you plan to use ternary operations in angular, you can do it by changing your syntax from

{{exp ? true : false}}

to

{{exp && '<value for true>' || '<value for false'}}

example:

<div> Total: {{bill.total == 0 && 'test' || 'test2' }} </div>

http://jsfiddle.net/KAgrw/9/

Fixed my fiddle :D

you have illegal characters in

{{ ( password == "qwerty") ? 'PASSED` : `NOT PASSED` }}

instead of ` you should use '

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top