Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display an empty string when a number is equal to 0 in angular expression

<div>{{a.value | number:0}}</div>

this is what I have. I would like to display just "" if the value is 0. Anyway I can do that within the same line? or I have to filter it out in a controller.

Thanks

like image 877
sammiwei Avatar asked Mar 17 '23 23:03

sammiwei


2 Answers

Pretty ugly but you can do it like this:

<div>{{a.value ? (a.value | number:0) : '' }}</div>

Not sure if there is more clearer way though.

like image 86
dfsq Avatar answered Mar 20 '23 11:03

dfsq


Use ng-bind and ng-if. Like this:

<span ng-bind="a.value" ng-if="a.value"></span>
like image 29
Kursad Gulseven Avatar answered Mar 20 '23 12:03

Kursad Gulseven