TypeError: Cannot read property 'taxTypeId' of undefined at Object.View_FullEditTaxComponent_0._co [as updateDirectives]

后端 未结 1 1147
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-06 13:25

I have a details form that should load the details of a record by when selected from the List Form. When the details form loads, it supposed to show the details of the selec

1条回答
  •  醉梦人生
    2021-01-06 13:46

    Since you're loading data asynchronously the tax property is undefined at first. And when angular performs change detection it is trying to get value from [(ngModel)]="tax.taxTypeId" binding and therefore you're getting the error.

    There are many ways to solve the issue:

    1) Safe navigation operator

    [ngModel]="tax?.taxTypeId" (ngModelChange)="tax.taxTypeId && tax.taxTypeId = $event"
    

    2) Initialize property with predefined value

    tax: TaxDto = new TaxDto();
    

    3) Wrap template in *ngIf="tax"

    
    

    0 讨论(0)
提交回复
热议问题