【发布时间】:2017-09-27 21:23:44
【问题描述】:
我的代码在开发模式下构建和运行完美。当我为生产构建时,我在这一行收到此错误:
<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 中,而不是 typescript。
【问题讨论】:
标签: angular angular-reactive-forms