生产构建中的 Angular4 编译错误:"Property controls does not exist on type AbstractControl"
Angular4 compile error on production build: "Property controls does not exist on type AbstractControl"
我的代码在开发模式下构建和运行完美。当我为生产构建时,我在这一行收到此错误:
<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']
至
meeting.controls.schedule['controls'].frequency
我的代码在开发模式下构建和运行完美。当我为生产构建时,我在这一行收到此错误:
<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 更改为此方法有效:
<div *ngFor="let child of form.controls.emailsArray['controls']; let i=index">
对我来说这解决了它:
改变
meeting.controls.schedule.controls['scheduleEnd']
至
meeting.controls.schedule['controls'].frequency