angular - 属性“_touched”是私有的,只能在“AbstractControl”类中访问。?
问题描述
生产构建错误
嗨,我在 Angular 项目中使用 ReactiveForms,当我尝试 ng build --prod 时出现以下错误
ng-details/billing-details.component.html (40,6): Property '_touched' is private and only accessible within class 'AbstractControl'.
下面是我的代码,我不知道出了什么问题?
paymentForm = new FormGroup({
companyName: new FormControl('', Validators.minLength(3)),
companyAddress: new FormControl('', Validators.minLength(3)),
gstNumber: new FormControl('', Validators.minLength(3)),
country: new FormControl('', Validators.minLength(3)),
cardNumber: new FormControl('', Validators.pattern('[0-9]{12}')),
cardName: new FormControl('')
});
html
<div class="common-error" *ngIf="paymentForm.controls.country._touched && !paymentForm.controls.country.valid"> Please enter Company Name. (Min 3 char)</div>
解决方案
为什么你提到_touched
财产,而不是touched
财产?
_touched
是 Angular 的内部实现细节。请仅使用公共变量。
尝试:
paymentForm.controls.country.touched
推荐阅读
- html - CSS根据最宽的元素将列向右对齐
- java - JxBrowser - 如何在多个组件中获取相同的浏览器会话
- reactjs - React Typescript 中用于自定义全局状态挂钩的显式类型
- excel - 将转发的电子邮件从 HTML 正文转换为纯文本,然后转换为 HTML 文本
- android - 错误:ADB exited with exit code 1 Performing Streamed Install 和与运行 abd 相关的错误
- python - 如何让Fabric使用默认shell的bash shell insread?
- python - 加载许多中文关键字的 Flashtext 问题
- react-native - 我不明白我的反应原生应用程序有什么问题 ///
- java - spring boot自动重启导致CommandLineRunner空异常
- vba - VBA - 创建对象以重定向“写入”方法