离子集控件表单构建器动态表单控件名称绑定 [英] Ionic set control form builder dynamic form control name binding
问题描述
我正在尝试创建一个具有不同表单组名称的单选按钮组并创建一个控件
I am trying to create a radio button group with different form group name and create a control
我的情况是,当我更改选择时,它会加载一个加载值的ajax或创建一个动态设置的单选按钮组
my scenario is when i change a select it loads ajax that loads values or to say creates dynamic set of radio button groups
在这里,当加载选择更改组时,一切都很好,但是所有问题都出现了,当我重新更改由小姐说的选择时,我基于创建单选按钮组选择了一个选项,并且当我更改回当前选项时,就出现了问题一个
here every thing is fine when select changes groups are loaded and all but the problem occurs when i re change the select say by miss i selected a option based on that the radio button group was created and when i change back to the current one
我认为控制器正在复制或未创建它会给我错误提示
I assume the controller is duplicating or not creating it gives me the error says
Error: There is no FormControl instance attached to form control element with name: 'action0'
<form [formGroup]="form">
<ion-row class="rows" *ngFor="let detail of details; let i = index">
<ion-col text-center="text-center" col-6="col-6">
{{your_data}}
</ion-col>
<ion-col class="rows last" col-6="col-6">
<ion-list class="row" no-lines="no-lines" radio-group="radio-group" formControlName="action{{i}}">
<ion-item col-4>
<ion-radio class="radio true" mode="md" value="true"></ion-radio>
</ion-item>
<ion-item col-4>
<ion-radio class="radio false" mode="md" value="false"></ion-radio>
</ion-item>
<ion-item col-4>
<ion-radio class="radio " mode="md" value="not sure"></ion-radio>
</ion-item>
</ion-list>
</ion-col>
</ion-row>
<button ion-button (click)="submit()" [disabled]="!form.valid">Submit</button>
</form>
.ts,响应成功后,选择位置发生了变化,我已将此代码放置了
.ts where the select is changing after success of the response i have placed this code
let i;
for(i in this.details){
this.form.setControl('action'+i, new FormControl(null, Validators.required));
}
推荐答案
I found the answer here it was dynamically creating form elements and when changed that was still present in the form and was not removed when second time select was changed
如果您遇到相同的问题,请在我的帮助下发表评论
Just drop a comment i vl help if you are facing the same issue
这篇关于离子集控件表单构建器动态表单控件名称绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!