在角度5中的三元运算符中返回模板插值

时间:2018-09-19 07:43:24

标签: angular5 string-interpolation angular-template

如何在angular 5模板中实现以下目标:

<h6>{{userWalletData.BTCWalletBalance ? {{userWalletData.BTCWalletBalance}} BTC = {{userWalletData.BTCWalletBalanceInFiat}} : 'Fetching balance...'}}</h6>

1 个答案:

答案 0 :(得分:2)

You can use Angular's *ngIf in the template to achieve it.

<h6 *ngIf="userWalletData.BTCWalletBalance != undefined && userWalletData.BTCWalletBalanceInFiat != undefined; else fetching_balance">{{userWalletData.BTCWalletBalance}} BTC = {{userWalletData.BTCWalletBalanceInFiat}}</h6>

<ng-template #fetching_balance><span>Fetching balance...</span></ng-template>

hope it helps!