Angularjs 仅当数据存在时显示文本前缀
我有一些AngularJS代码,只有当它们是要显示的余额时,才会显示未付余额Angularjs 仅当数据存在时显示文本前缀,angularjs,Angularjs,我有一些AngularJS代码,只有当它们是要显示的余额时,才会显示未付余额 {{Customer.LastName}}, {{Customer.FirstName}} ${{Customer.OutstandingBalance}} 如果没有未清余额,我想做的是根本不显示美元符号($)。如何使美元符号取决于客户的值。未结清余额?您可以有一个仅基于未结清余额显示的跨度: <span ng-show="Customer.OutstandingBalance != 0">$</s
{{Customer.LastName}}, {{Customer.FirstName}} ${{Customer.OutstandingBalance}}
如果没有未清余额,我想做的是根本不显示美元符号($)。如何使美元符号取决于
客户的值。未结清余额
?您可以有一个仅基于未结清余额
显示的跨度:
<span ng-show="Customer.OutstandingBalance != 0">$</span> {{Customer.OutstandingBalance}}
${{Customer.OutstandingBalance}
您可以有一个仅基于未结清余额显示的跨度
:
<span ng-show="Customer.OutstandingBalance != 0">$</span> {{Customer.OutstandingBalance}}
${{Customer.OutstandingBalance}
我认为除了一些明显的建议,比如“用
你可以这样做:{code>{{Customer.LastName}},{{Customer.FirstName}{{Customer.outstandinbalance?'$':''}}{{{Customer.outstandinbalance}}我想除了一些明显的建议,比如“用
包装它”
您可以这样做:
{{Customer.LastName}},{{Customer.FirstName}{{Customer.outstandinbalance?'$':''}}{{{Customer.outstandinbalance}}
使用内置货币文件管理器的自定义过滤器
app.filter('myCurrency', function($filter){
return function(input){
return input ? $filter('currency')(input) : '';
};
});
考虑使用
{{Customer.LastName}}, {{Customer.FirstName}} {{Customer.OutstandingBalance | myCurrency}}
这是plunker演示
使用内置货币文件管理器的自定义过滤器
app.filter('myCurrency', function($filter){
return function(input){
return input ? $filter('currency')(input) : '';
};
});
考虑使用
{{Customer.LastName}}, {{Customer.FirstName}} {{Customer.OutstandingBalance | myCurrency}}
这是plunker演示
a将需要隐藏美元符号。@MamaWalter是正确的,需要使用一些自定义文件管理器。单靠有棱角的固有货币是无济于事的。我已经更新了隐藏美元符号所需的应答。@MamaWalter是正确的,需要使用一些自定义文件管理器。单靠有棱角的固有货币是无济于事的。我已经更新了答案