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