admin管理员组

文章数量:1245684

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 badges
Add a ment  | 

3 Answers 3

Reset to default 6

You 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 '

本文标签: javascriptUsing of ternary operator in viewStack Overflow