AngularJS - Using ternary operators and filters within a binding

Oam Psy picture Oam Psy · Oct 17, 2014 · Viewed 11k times · Source

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?

Answer

Rahil Wazir picture Rahil Wazir · Oct 17, 2014

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

{{ (myAccount.Balance > 0 ? myAccount.Balance : myAccount.Balance + 'minus') | filter | filter 2 }}