【问题标题】:How to put ng for and ng if in <options> angular 6?如果在 <options> angular 6 中,如何将 ng for 和 ng 放入?
【发布时间】:2019-09-05 07:29:11
【问题描述】:

我需要在

上使用 ngIf 和 ngFor
<option *ngFor="let price of product['pricingDetails']" *ngIf="price['chainPrice']" >

但它显示Can't have multiple template bindings on one element. Use only one attribute prefixed with * 错误。在元素中同时使用两者的最佳方式是什么?

【问题讨论】:

标签: html angular6


【解决方案1】:

试试这个,

<select>

<ng-container *ngFor="let price of product['pricingDetails']">
<option  *ngIf="price['chainPrice']" >
   {{ display anythjing }}
</option>

</ng-container>
</select>


试试我更新的代码。

【讨论】:

  • 我要问的是我只需要 *ngIf 用于选项。上述方法将产生空选项元素
  • 这仍然会创建一个选项。那只是没有任何东西,但仍然会创建选项。我猜这不是必需的。
【解决方案2】:

使用这个:

[hidden]="!price['chainPrice']"

而不是这个:

*ngIf="price['chainPrice']"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-24
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    相关资源
    最近更新 更多