【发布时间】:2019-04-23 04:10:32
【问题描述】:
我是 angular 新手。目前我正在开发一个使用 angular 作为前端和 php laravel 作为 api 的项目。我从这样的 api 得到一个结果集
{
"status":1,
"msg":"Success",
"result":{
"current_page":1,
"data":[
{
"id":3,
"name":"Sooraj Account II",
"email":"sfdsf@sfdf.com",
"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
}
}
我把这个结果集称为这样的角度
<ng-container *ngFor="let brkrleads of result.data">
....
</ng-container>
但是当我使用 result.data 时,我遇到了这个错误
BrokerleadsComponent.html:70 错误类型错误:无法读取属性 未定义的“数据”
我不知道为什么会出现这个错误,请任何人帮忙。
【问题讨论】:
-
你可以试试这个
<ng-container *ngIf="result.data" *ngFor="let brkrleads of result.data"> .... </ng-container>吗?二、尝试console.log(result)。
标签: angular typescript