我有看起來像這樣的 html:
<as-split unit="pixel" #mainViewSplit class="custom-gutter" direction="horizontal" gutterSize="2">
<ng-container *ngFor="let splitItem of splitData">
<as-split-area [id]="splitItem.id" *ngIf="(splitItem.isVisible$ | async)"
[order]="splitItem.order">
<ng-container *ngTemplateOutlet="splitItem.template"></ng-container>
</as-split-area>
</ng-container>
</as-split>
這適用于具有 id 的拆分專案。但是其中一些是未定義的,因此在 html 中根本不應該有 id。但是對于沒有 id html 的專案看起來像這樣:
id="undefined"
我也試過
[id]="splitItem.id ? splitItem.id : null"
因為這個問題中的評論建議使用null,但它不起作用。它只會導致
id="null"
如何設定系結以使html中根本沒有id?
uj5u.com熱心網友回復:
如果 splitItem.id 的值未定義,則使用 [attr.id] 代替 [id] 屬性 id 將不會添加到 DOM 中
<as-split-area
[attr.id]="splitItem.id"
*ngIf="splitItem.isVisible$ | async"
[order]="splitItem.order"
>
<ng-container *ngTemplateOutlet="splitItem.template"></ng-container>
</as-split-area>
uj5u.com熱心網友回復:
您是否嘗試過使用index而不是id?這樣 您將在屬性 [id] 中獲得一個數字,而不是undefined 。
遵循這個:-
*ngFor="讓 splitData 的 splitItem;讓 i = index"
然后在你的 <as-split-area [id]="i">
uj5u.com熱心網友回復:
如果未定義,您可以將 id 設定為空字串。像這樣
[id]="splitItem.id ? splitItem.id : ''"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/532591.html
標籤:有角度的
上一篇:在Angularapp.component.ts中使用JavaScript函式
下一篇:聊天未在Iphone中顯示