简体   繁体   English

如何在角度表达式中数字等于0时显示空字符串

[英]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? 如果值为0,我想显示“”无论如何,我可以在同一行内做到这一点? or I have to filter it out in a controller. 或者我必须在控制器中过滤掉它。

Thanks 谢谢

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. 不确定是否有更清晰的方式。

Use ng-bind and ng-if . 使用ng-bindng-if Like this: 像这样:

<span ng-bind="a.value" ng-if="a.value"></span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM