【问题标题】:Property 'controls' does not exist on type 'AbstractControl' - angular8“AbstractControl”类型上不存在属性“控件” - angular8
【发布时间】:2020-05-28 19:09:33
【问题描述】:

在我拥有的组件中

  @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 模式下出现错误 “AbstractControl”类型上不存在属性“控件”。

【问题讨论】:

    标签: angular angular8 angular-reactive-forms


    【解决方案1】:

    当您在代码中出现错误时,Angular 会显示此类问题。 有时没有信息... 良好的做法是为控件执行多个 getter。

    【讨论】:

      【解决方案2】:

      试试看

      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>
      

      【讨论】:

        猜你喜欢
        • 2018-11-05
        • 1970-01-01
        • 2023-03-03
        • 2018-01-26
        • 2021-08-13
        • 2019-03-07
        • 2019-04-11
        • 2019-10-10
        • 1970-01-01
        相关资源
        最近更新 更多