我的代码在开发模式下构建并完美地运行。当我为生产构建时,我会在此行上获得此错误:
<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中引用这些子控制器?
注意:与此问题类似,除了我的错误在HTML中发生,而不是打字稿。
我不确定这是否是好练习,但是将html更改为有效:
<div *ngFor="let child of form.controls.emailsArray['controls']; let i=index">
对我而言,这解决了:
更改
meeting.controls.schedule.controls['scheduleEnd']
to
meeting.controls.schedule['controls'].frequency