我新的角度,假設我有值的這樣如何在angular4中使用ngFor時根據值選擇HTML?
domElement:Array<boolean>=[true,false,false,false,false,true,true,true];
一個數組,我想真正的價值觀和不同的HTML假值不同的HTML,而使用ngFor,我跟着這個blog並實現這一點,但它不起作用
即。
<div *ngFor="let n of domElement; let i=index">
<div *ngFor="let n of num; let i=index">
<ng-template *ngIf="n; then gotValue else noValue"></ng-template>
<ng-template #noValue>
<div class="alert alert-warning">
no value found - dummy element for no record !!!
</div>
</ng-template>
<ng-template #gotValue>
<div class="alert alert-success">
got values !!!
</div>
</ng-template>
</div>
我試圖實現這一點,但無論價值是什麼我總是得到顯示,請參閱我的更新問題,謝謝 –
如果我的新實現不適合您,請與我們分享組件代碼。這可能會導致n等於'undefined',這意味着if子句會自動將您重定向到false塊。 –