拨动开关在 angular 反应形式内不起作用
Toggle switch not working inside angular reactive form
在我的 angular 6 应用程序中,我使用 angular 反应形式,它在 formarray 中有一个三态切换开关。
Html 具有三个状态切换:
<div class="switch-toggle switch-3 switch-candy">
<ng-container #buttonIcon *ngFor="let option of options" >
<input
type="radio"
formControlName="state"
[id]="option"
[value]="option" />
<label
[attr.for]="option">
{{option}}
</label>
</ng-container><a></a>
</div>
工作 stackblitz:
https://stackblitz.com/edit/disable-group-control-value-on-another-control-value-for-kqhsvy
请点击上面的add
按钮link查看输入。
例如..,点击添加按钮三次,因此添加了三行,这里第一行的切换开关单独工作,其余行的切换不工作..即使切换是在第二行或第三行进行的只更改了第一行..
请帮助我使每行的切换开关唯一,并分别检索每行中切换的值..
这是因为你所有的label和input的id都是一样的。将 html 更改为
<div class="switch-toggle switch-3 switch-candy">
<ng-container #buttonIcon *ngFor="let option of options" >
<input
type="radio"
formControlName="state"
[id]="option+i"
[value]="option" />
<label
[attr.for]="option+i">
{{option}}
</label>
</ng-container><a></a>
</div>
在我的 angular 6 应用程序中,我使用 angular 反应形式,它在 formarray 中有一个三态切换开关。
Html 具有三个状态切换:
<div class="switch-toggle switch-3 switch-candy">
<ng-container #buttonIcon *ngFor="let option of options" >
<input
type="radio"
formControlName="state"
[id]="option"
[value]="option" />
<label
[attr.for]="option">
{{option}}
</label>
</ng-container><a></a>
</div>
工作 stackblitz:
https://stackblitz.com/edit/disable-group-control-value-on-another-control-value-for-kqhsvy
请点击上面的add
按钮link查看输入。
例如..,点击添加按钮三次,因此添加了三行,这里第一行的切换开关单独工作,其余行的切换不工作..即使切换是在第二行或第三行进行的只更改了第一行..
请帮助我使每行的切换开关唯一,并分别检索每行中切换的值..
这是因为你所有的label和input的id都是一样的。将 html 更改为
<div class="switch-toggle switch-3 switch-candy">
<ng-container #buttonIcon *ngFor="let option of options" >
<input
type="radio"
formControlName="state"
[id]="option+i"
[value]="option" />
<label
[attr.for]="option+i">
{{option}}
</label>
</ng-container><a></a>
</div>