Angular 5 - Observable Return Error Cannot Read Property Of Undefined
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 correct response with th
Solution 1:
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.
Post a Comment for "Angular 5 - Observable Return Error Cannot Read Property Of Undefined"