【发布时间】:2019-09-18 05:34:07
【问题描述】:
在不使用 ng-model 的情况下,无法从 for 循环设置索引值以形成角度控制,有什么方法可以实现吗?
<div formArrayName="sample" *ngFor="let a of getControls(sampledata, 'sample'); let i = index">
<div [formGroupName]="i">
<input type="text" formControlName="index" name="index" value="{{ i }}"
/>
<input
formControlName="dx"
type="text"
class="form-control"
/>
</div>
</div>
//form Group
this.sampledata= new FormGroup({
sample: new FormArray([this.createArray()])
});
//Form Array
createArray(){
return this.formBuilder.group({
dx: null,
index:null
})
//Creation of array dynamically
getControls(frmGrp: FormGroup, key: string) {
return (<FormArray>frmGrp.controls[key]).controls;
}
【问题讨论】:
-
您能否提及您的表单组?
-
hi @ng-suhas 查看我的问题,它是从组更新的
-
我已经给出了答案。希望对您有所帮助。
标签: angular angular-reactive-forms