【问题标题】:angular add label to checkboxes created with *ngFor将标签添加到使用 *ngFor 创建的复选框
【发布时间】:2018-07-03 21:27:24
【问题描述】:

我正在使用角度 5

我正在使用下面的代码来创建多个复选框,并且需要给它们标签

<input type="checkbox" *ngFor = "let v of options[0].options" [value]="1" [name] = "1">

当使用 HTML 时,我会使用

如何在 *ngFor 中使用标签并创建合适的标签?

谢谢

【问题讨论】:

  • 需要的选项数据请在您的问题中发布

标签: html angular angular5


【解决方案1】:
<label *ngFor = "let v of options[0].options">
    <input type="checkbox">
</label>

或者你可以使用ng-container

<ng-container *ngFor = "let v of options[0].options">
    <label for...></label>
    <input ...>
</ng-container>

【讨论】:

    【解决方案2】:

    你可以试试这个解决方案。

    <div class="checkbox" *ngFor = "let v of options[0].options">
        <label>
            <input type="checkbox"  [value]="v.value">{{v.name}}
        </label>
    </div> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-17
      • 2018-12-10
      • 2016-06-23
      • 2016-11-22
      • 2019-01-07
      • 2013-04-23
      • 1970-01-01
      • 2019-01-14
      相关资源
      最近更新 更多