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/
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ), then an expression to execute if the condition is truthy followed by a colon ( : ), and finally the expression to execute if the condition is falsy.
Example: C Ternary Operator Here, age >= 18 - test condition that checks if input value is greater or equal to 18. printf("You can vote") - expression1 that is executed if condition is true. printf("You cannot vote") - expression2 that is executed if condition is false.
Example 1: C# Ternary Operator In the above program, 2 is assigned to a variable number . Then, the ternary operator is used to check if number is even or not. Since, 2 is even, the expression ( number % 2 == 0 ) returns true . We can also use ternary operator to return numbers, strings and characters.
Ternary operator is a Conditional operator in C#. It takes three arguments and evaluates a Boolean expression.
You need to use angular 1.1.5+/1.2+. Which version of angular are you using?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With