Recently, I started using Angular for a project that utilizes Angular for the front end and PHP Laravel for the API. The API is returning a result set structured like this:
{
"status":1,
"msg":"Success",
"result":{
"current_page":1,
"data":[
{
"id":3,
"name":"Sooraj Account II",
"email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7a4b1b3a4b197a4b1b3b1f9b4b8ba">[email protected]</a>",
"phone":"2134234234",
"send_on":"17 \/ Apr \/ 2019",
"listing_heading":"Listing three1",
"listing_id":2
}
],
"first_page_url":"http:\/\/localhost:8000\/api\/auth\/getLeadsByBroker?page=1",
"from":1,
"last_page":2,
"last_page_url":"http:\/\/localhost:8000\/api\/auth\/getLeadsByBroker?page=2",
"next_page_url":"http:\/\/localhost:8000\/api\/auth\/getLeadsByBroker?page=2",
"path":"http:\/\/localhost:8000\/api\/auth\/getLeadsByBroker",
"per_page":1,
"prev_page_url":null,
"to":1,
"total":2
}
}
In my Angular code, I'm trying to access this result set as follows:
<ng-container *ngFor="let brkrleads of result.data">
....
</ng-container>
However, when I attempt to use result.data, I encounter the following error:
BrokerleadsComponent.html:70 ERROR TypeError: Cannot read property 'data' of undefined
I'm puzzled by this error and would appreciate any assistance in resolving it.