Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using of ternary operator in view

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/

like image 785
Ivan Chernykh Avatar asked Oct 21 '13 10:10

Ivan Chernykh


People also ask

What is the use of ternary operator?

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.

What is ternary operator example?

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.

How can use ternary operator for 3 conditions in C#?

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.

What is a ternary operator in C#?

Ternary operator is a Conditional operator in C#. It takes three arguments and evaluates a Boolean expression.


1 Answers

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

like image 133
Foo L Avatar answered Oct 30 '22 11:10

Foo L