显示来自httpClient的Angular4响应数据
我有来自Angular 4的代码 我在控制台中有这个(数组对象)响应显示来自httpClient的Angular4响应数据,angular,ngfor,Angular,Ngfor,我有来自Angular 4的代码 我在控制台中有这个(数组对象)响应 我想在*ngFor中使用这些数据来迭代这些对象,我怎样才能得到这些?谢谢。因为您使用了{observe:'reaponse'}作为HttpClient.get,会有完整的响应(标题和正文)返回,您可以使用*ngFor对数据进行迭代器。body将其作为公共变量公开,如下所示: data: any; this.http.get(..., {observe: 'response'}) .subscribe(data =
我想在
*ngFor
中使用这些数据来迭代这些对象,我怎样才能得到这些?谢谢。因为您使用了{observe:'reaponse'}
作为HttpClient.get
,会有完整的响应(标题和正文)返回,您可以使用*ngFor
对数据进行迭代器。body
将其作为公共变量公开,如下所示:
data: any;
this.http.get(..., {observe: 'response'})
.subscribe(data => this.data = data.body);
data: any;
this.http.get(...) // without observe: response
.subscribe(data => this.data = data);
模板代码示例:
<div *ngFor="let item of data">
{{item.address}}
</div>
<div *ngFor="let item of data">
{{item.address}}
</div>
<div *ngFor="let item of data$ | async">
{{item.address}}
</div>
模板代码示例:
<div *ngFor="let item of data">
{{item.address}}
</div>
<div *ngFor="let item of data">
{{item.address}}
</div>
<div *ngFor="let item of data$ | async">
{{item.address}}
</div>
模板代码示例:
<div *ngFor="let item of data">
{{item.address}}
</div>
<div *ngFor="let item of data">
{{item.address}}
</div>
<div *ngFor="let item of data$ | async">
{{item.address}}
</div>
{{item.address}