我的代码在开发模式下构建并完美运行。当我为生产而构建时,我在这一行上得到了这个错误:
<div *ngFor="let child of form.controls.emailsArray.controls; let i=index">
表单构建如下:
public form: FormGroup;
private control: FormArray;
private emailsModel = { emails: ['','','','','']} // the model, ready to hold the emails
private fb : FormBuilder;
constructor() {}
ngOnInit() {
this.fb = new FormBuilder;
this.form = this.fb.group({
emailsArray: this.fb.array([])
});
this.control = <FormArray>this.form.controls['emailsArray'];
this.patch();
}
private patch(): void {
// iterate the object model and extra values, binding them to the controls
this.emailsModel.emails.forEach((item) => {
this.control.push(this.patchValues(item));
})
}
private patchValues(item: string): AbstractControl {
return this.fb.group({
email: [item, Validators.compose([emailValidator])]
})
}
那么如何在html中引用这些子控件?
注意:类似于this question,但我的错误发生在HTML中,而不是打字稿。
答案 0 :(得分:6)
我不确定这是不是很好的做法,但将HTML更改为有效:
<div *ngFor="let child of form.controls.emailsArray['controls']; let i=index">
答案 1 :(得分:1)
对我来说,这解决了它:
更改
meeting.controls.schedule.controls['scheduleEnd']
到
meeting.controls.schedule['controls'].frequency