Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS - Using ternary operators and filters within a binding

I current have a simple data binding:

{{ myAccount.Balance }}

I think applied a couple of filters:

{{ myAccount.Balance | filter1 | filter2 }}

However, i want to use a ternary operator when the Balance is less than zero, the below works (without the filters):

{{ myAccount.Balance > 0 ? myAccount.Balance : myAccount.Balance + 'minus' }}

How can i use my filters 1 and 2 in the above too?

like image 821
Oam Psy Avatar asked Oct 17 '14 10:10

Oam Psy


1 Answers

You need to wrap them in parenthesis () to take precedency

{{ (myAccount.Balance > 0 ? myAccount.Balance : myAccount.Balance + 'minus') | filter | filter 2 }}
like image 150
Rahil Wazir Avatar answered Nov 09 '22 02:11

Rahil Wazir