Cannot read property of 'xxx' of undefined

前端 未结 1 1275
我寻月下人不归
我寻月下人不归 2020-11-29 11:46

I\'m using Ionic 2, in which a component has two components and the data were shared using emitters. But when I execute the program, it comes to this error.

相关标签:
1条回答
  • 2020-11-29 12:01

    The view is loaded before billItem is set.

    You could use a safe navigation operator ?.

    <ion-input text-right type="text" [value]="billItem?.BillNo" readonly></ion-input> //billItem model has BillNo property
    

    or set it to empty object in the constructor of bill-details.ts:

    constructor(...){
      if(! this.billItem){
        this.billItem={}
      }
    }
    
    0 讨论(0)
提交回复
热议问题