首页 > 解决方案 > 属性“_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>

标签: angularangular-reactive-forms

解决方案


为什么你提到_touched财产,而不是touched财产?

_touched是 Angular 的内部实现细节。请仅使用公共变量。

尝试:

paymentForm.controls.country.touched

推荐阅读