Stealth Rabbi Stealth Rabbi - 1 year ago 63
AngularJS Question

optionall adding text at the end of an angular expression

I have an expression that's pull data from a controller, the number of pages of a book.

If the data exists, I want to print "X pages", where X is the value. Otherwose, I want the HTML paragraph to be blank.

But, I can't get the syntax correct. Below, it always prints out ' pages', even if blank. How do I set up my expression?

<p>{{ + ' pages' || "" }}</p>

I tried doing ternary operator in the expression, but didn't have lukc

<p>{{( > 0)?{{ + ' pages' :"" }}</p>

Answer Source


<p ng-if="">{{ }} pages</p>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download