Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline-logic in templates in AngularJS

Is there any way to write logic inline in a template in AngularJS.

What I want to do is something like this:

<div ng-repeat="item in items">     {{item.isValid ? 'Valid item' : 'Invalid Item'}} </div> 
like image 887
Seb Nilsson Avatar asked Mar 14 '13 12:03

Seb Nilsson


1 Answers

You can use && and ||, which will end up working just like the ternary operators.

{{item.isValid && 'Valid' || 'Invalid' }}

EDIT: Angular introduced ternary operators in 1.1.5:

{{item.isValid ? 'Valid' : 'Invalid' }}

like image 79
Andrew Joslin Avatar answered Sep 22 '22 02:09

Andrew Joslin