Angular 如何对子组中的项目进行角度为2/4/5的阵列集控制(setControl)
我有表格Angular 如何对子组中的项目进行角度为2/4/5的阵列集控制(setControl),angular,Angular,我有表格 this.form = this.fb.group({ displayName: [user.displayName, Validators.required], profile: this.fb.group({ gender: [user.profile.gender, Validators.required], birthday: [user.profile.birthday, Validators.required], place_of_birth
this.form = this.fb.group({
displayName: [user.displayName, Validators.required],
profile: this.fb.group({
gender: [user.profile.gender, Validators.required],
birthday: [user.profile.birthday, Validators.required],
place_of_birth: [user.profile.place_of_birth, Validators.required],
place_of_residence: [user.profile.place_of_residence, Validators.required],
about_me: [user.profile.about_me, Validators.required],
interests: [user.profile.interests, Validators.required],
sport: [user.profile.sport, Validators.required],
highSchool: this.fb.array(educationFGs)
})
});
高中是“来自”组中“个人资料”组中的一个项目
我只需要更新高中
在我做这件事之前:
this.educations.splice(index, 1);
const educationFGs = this.educations.map(education => this.fb.group(education));
const educationArray = this.fb.array(educationFGs);
this.form.setControl('highSchool', educationArray);
但当我以小组形式进入高中后,我不知道如何进入它
这对我不起作用:
this.form.setControl('profile.highSchool',educationArray)代码>解决方案是通过获取和推送新val访问表单控件
add() {
const fa = this.form.get('profile.highSchool') as FormArray;
fa.push(this.fb.group({
name: '',
date: ''
}));
}
要删除项目,请使用removeAt
remove(index) {
const fa = this.form.get('profile.highSchool') as FormArray;
fa.removeAt(index);
}