如何动态绑定 formControl 值?
How to bind formControl value dynamically?
我正在尝试在循环中动态地将 formControl 值绑定到输入元素上。
<div *ngFor="let value of values">
<input attr.formControl="{{value}}" type="text"/>
</div>
这是行不通的。 formControl 属性不是标准 html 属性,所以我想必须有一些其他方法来绑定值。
通常formControll是这样绑定的
[formControl]="name"
这应该可以解决问题:
<div *ngFor="let value of values">
<input [formControlName]="value" type="text"/>
</div>
我正在尝试在循环中动态地将 formControl 值绑定到输入元素上。
<div *ngFor="let value of values">
<input attr.formControl="{{value}}" type="text"/>
</div>
这是行不通的。 formControl 属性不是标准 html 属性,所以我想必须有一些其他方法来绑定值。
通常formControll是这样绑定的
[formControl]="name"
这应该可以解决问题:
<div *ngFor="let value of values">
<input [formControlName]="value" type="text"/>
</div>