使用命令ng build --prod
构建角度应用程序时出现以下错误。
错误:
edit.component.html(111,50): Property 'controls' does not exist on type 'AbstractControl'.
edit.component.html(113,54): Property 'controls' does not exist on type 'AbstractControl'
我在下面解释我的代码。
<div *ngIf="storeForm.get('Address').controls['AddressLine1'].invalid && (storeForm.get('Address').controls['AddressLine1'].dirty || storeForm.get('Address').controls['AddressLine1'].touched)"
class="alert alert-danger">
<div *ngIf="storeForm.get('Address').controls['AddressLine1'].errors.required">
AddressLine1 is required.
</div>
</div>
this.storeForm = this.fb.group({
Address: this.fb.group({
AddressLine1: ['', Validators.required],
}),
});
在构建应用程序时,我需要忽略那些警告消息,而我正在使用Angular cli-8.2.1
。
答案 0 :(得分:0)
请在下面找到有效的解决方案-
.ts文件
refetch
在模板文件中,而不是
Query
使用此
myForm: FormGroup;
ngOnInit() {
this.myForm = this.fb.group({
testimonials: new FormArray([])
});
this.getInitialForms();
}
// THIS IS IMPORTANT
// getter - (accessed as this.testimonialsForm in this file)
get testimonialsForm() { return this.myForm.get('testimonials') as FormArray; }
getInitialForms() {
this.testimonialsForm.push(
this.fb.group({
name: ['', Validators.required],
designation: ['', Validators.required],
testimonial_text: ['', Validators.required]
})
);
}
我在角度8时遇到了同样的错误,对我来说效果很好。
如果您有任何问题,请告诉我。