I'm unable to get JSON data on the page after Interpolation in Ionic 2

后端 未结 1 910
忘了有多久
忘了有多久 2021-01-25 04:21

I\'m very new to Ionic 2 and i\'ve found myself stuck with an issue. I\'m unable to see the data printing on the page, it throws an error everytime, but I\'m able to see the API

相关标签:
1条回答
  • 2021-01-25 04:49

    Your md field is initialized asynchronously in your code. So if the template renders before the response arrives: undefined.title will throw an error.

    Either initialize your object,

    md: any = {};
    

    or use the safe-navigation operator (?),

     {{md?.title}}
    

    or use an *ngIf to check whether your object is valid or not,

    <div *ngIf="md">
        {{md.title}}
    </div>
    
    0 讨论(0)
提交回复
热议问题