1

I have to display either 0 or 1 in {{}} in HTML page. my controller has a property based on which i have to decide wether to display 0 or to display 1. If the property is greater than or equal to one then 1 should be displayed, 0 otherwise.

Any suggestions or tricks ?

Note: I want to do this in HTML code itself using angularJS tricks.

Please Help

1 Answers1

1

Angular supports expressions

you can use a ternary operator inside expressions

<span> {{ property >= 1 ? 1 : 0 }} </span>

Alternatively, or you can use a filter

app.filter("myFilter",function){
   return function(number){
     return number >=1 ? 1 : 0;
   }
})

and use it like so:

<span> {{ property | myFilter }} </span>
Community
  • 1
  • 1
Ilan Frumer
  • 32,059
  • 8
  • 70
  • 84