属性'controls'在'AbstractControl'类型上不存在 - angular8

问题描述 投票:0回答:1

在组件我有

  @Input() CaseFormIn: FormGroup;
get f() { return this.CaseFormIn.controls; }

在模板中

 <div class="error-message" *ngIf="this.f.generalInfoFormGroup.controls.primaryStore.touched&&this.f.generalInfoFormGroup.controls.primaryStore.errors">
           Primary Store is a Required Field.
        </div>

在开发代码中工作正常,但在prod模式下得到以下错误属性'controls'在'AbstractControl'类型中不存在。

angular angular8 angular-reactive-forms
1个回答
1
投票

试一试

get primaryStore() { return (this.CaseFormIn.controls.generalInfoFormGroup as FormGroup).controls.primaryStore; }

而在模板

 <div class="error-message" *ngIf="primaryStore.touched && primaryStore.errors">
      Primary Store is a Required Field.
 </div>

0
投票

当你的代码出错时,Angular就会出现这种问题,有时会出现没有信息的情况......另外,好的做法是为控件做多个getter。

© www.soinside.com 2019 - 2024. All rights reserved.