我是 Angular 的新手,當沒有資料可顯示時,我需要幫助來顯示訊息。
這是我的 component.html 部分:
<app-header [isHidden]="isHiddenProgressBar"></app-header>
<div >
<button (click)="changeState()" *ngIf="showButton" color="primary" mat-raised-button>Change state</button>
</div>
<div >
<app-list *ngIf="visible" [changeObjects]="data"></app-list>
</div>
我在 .ts 檔案中有一個布林值,如下所示:
this.data = this.objects;
this.visible = this.objects != null && this.objects.length > 0;
this.showButton = true;
}
如果有資料要顯示,我希望組件顯示串列,否則我希望顯示類似“串列為空”的訊息。
感謝您的幫助!
uj5u.com熱心網友回復:
當引數不真實時,您可以使用ngIf指令進行渲染ng-template。您可以在此處閱讀更多內容。
您的代碼示例:
<app-list *ngIf="visible; else #notVisible" [changeObjects]="data"></app-list>
<ng-template #notVisible>The list is empty.</ng-template>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/339570.html
標籤:有角的
上一篇:角度變數值更改未反映在DOM中
