Search code examples
angular5string-interpolationangular-template

return template interpolation within ternary operator in angular 5


How do achieve following in angular 5 template:

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

Solution

  • 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!