【问题标题】:How to bind in angular conditionally in *ngFor?如何在 *ngFor 中有条件地绑定角度?
【发布时间】:2022-11-12 04:18:00
【问题描述】:

我有看起来像这样的 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"

因为this问题中的评论建议使用null,但它不起作用。它只会导致

id="null"

如何设置绑定以使html中根本没有id?

【问题讨论】:

    标签: angular


    【解决方案1】:

    您是否尝试过使用指数代替ID? 所以,而不是不明确的你会得到一个数字在属性 [id] 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-21
      • 2021-10-04
      • 1970-01-01
      • 2019-09-20
      • 1970-01-01
      • 1970-01-01
      • 2020-01-05
      • 1970-01-01
      相关资源
      最近更新 更多