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: /
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/cherniv/KAgrw/
Share Improve this question asked Oct 21, 2013 at 10:28 Ivan ChernykhIvan Chernykh 42.2k13 gold badges136 silver badges148 bronze badges3 Answers
Reset to default 6You need to use angular 1.1.5+/1.2+. Which version of angular are you using?
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/KAgrw/9/
Fixed my fiddle :D
you have illegal characters in
{{ ( password == "qwerty") ? 'PASSED` : `NOT PASSED` }}
instead of ` you should use '