angular - Display Angular4 Response Data From httpClient Iteration ngFor -


i have code angular 4

enter image description here.

and have (array objects)response in console

enter image description here.

and want use data in *ngfor iterate objects, how can this? thanks.

since used {observe: 'reaponse'} httpclient.get, there full response(both header , body) back, can use *ngfor iterator data.body exposing public variable below:

data: any;  this.http.get(..., {observe: 'response'})     .subscribe(data => this.data = data.body); 

template code sample:

<div *ngfor="let item of data">   {{item.address}} </div> 

httpclient.get return body of response default without {observe: 'response'}. can achieve without {observe: 'response'} below:

data: any;  this.http.get(...)   // without observe: response     .subscribe(data => this.data = data); 

template code sample:

<div *ngfor="let item of data">   {{item.address}} </div> 

also can use async pipe subscribe , unsubscribe template without expose data public variable:

data$: any;  this.data$ = this.http.get(...) // or  this.data$ = this.http.get(..., {observe: 'reaponse'}).map(data => data.body); 

template code sample:

<div *ngfor="let item of data$ | async">   {{item.address}} </div> 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -