ionic3 post返回的数据 不能ngFor
通过post返回的数据进行循环
.ts
this.dataInsdustry = data.result;.html
<ul> <li *ngFor="let item of dataInsdustry"> {{item}} </li> </ul>
post 返回的数据不能ngFor时,报错详情为:
其中的post数据:
出现这种情况,需要将返回的json数据转换:
public arrayOfKeys:any;
constructor( public navCtrl: NavController, public navParams: NavParams,
) {
this.dataInsdustry = data.result; this.arrayOfKeys = Object.keys(this.dataInsdustry);
}.html
<ion-item *ngFor="let key of arrayOfKeys"> <ion-label>{{key}}{{dataInsdustry[key]}}</ion-label> </ion-item>展示:
参考:https://stackoverflow.com/questions/35647365/how-to-display-json-object-using-ngfor