Angular 5 - Observable return error cannot read property of undefined

后端 未结 1 1156
情书的邮戳
情书的邮戳 2021-01-22 03:33

I\'m starting to implement a simple pagination using Spring Rest and Angular 5 inside my angular service when I call my web service using httpClient a get a cor

1条回答
  •  再見小時候
    2021-01-22 04:14

    Because the getPageClient function is asynchronous, pageClient is undefined when the page first loads. That means when doing pageClient.content, you will get an error.

    Thankfully, Angular provides a useful bit of syntax you can use in the template to avoid this. You should use *ngIf="pageClient?.content" > instead.

    The ? tells Angular to only read content if pageClient is not null / undefined.

    More info here

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