angular - 在构建角度应用程序时收到一些警告消息
问题描述
使用命令构建角度应用程序时出现以下错误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
.
解决方案
请在下面找到工作解决方案 -
.ts 文件
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]
})
);
}
而在模板文件中,而不是
myForm.get('testimonials').controls
用这个
testimonialsForm.controls
我在使用 angular 8 时遇到了同样的错误,它对我来说非常好。
如果您有任何问题,请告诉我。
推荐阅读
- flutter - 将颜色值返回到变量中
- c++ - 从 const std::string& 移动到 std::string_view 时的向后兼容性考虑?
- json - 如何在 Visual Studio Community 2019 中格式化 JSON 文档?
- android - 如何在 Android 上接收实时 API 数据更新?
- laravel - 什么是 ”??” 刀片模板中的符号
- xml - XSL 从 MultipleXML 字段创建新元素,包括一些具有相同名称的字段
- c# - C# BulkCopy.WriteToServer 更改值
- python - 将 python selenium webdriver 保持在后台/不集中
- javascript - 使用 pdf.js 渲染 pdf 文档时出现空白页
- c++ - 假设我们有一个右值引用,这个右值是持久的吗?