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

2
  • Use ?: operator, it is supported in {{}} Commented Jan 10, 2014 at 10:08
  • What's your controller property? {{ property === "something" ? 1 : 0 }} Commented Jan 10, 2014 at 10:08

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.