저는 이온 2를 학습 중이며 현재 일부 이온 수명 문제에 직면 해 있습니다. API가 성공 데이터를 얻은 후에 데이터를 표시하려고합니다.ionic 2는 데이터를보기 전에로드합니다.
import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
import {LoadingController} from 'ionic-angular';
import WooCommerceAPI from 'woocommerce-api';
@Component({
selector: 'page-category',
templateUrl: 'category.html',
})
export class CategoryPage {
information: any[] = [];
infoChild: any[] = [];
wooApi: any;
wooCat: any;
categories: any = [];
constructor(public navCtrl: NavController, public loadingCtrl: LoadingController) {
this.wooApi = WooCommerceAPI(
{
url: 'abc.com/api/v1/cat',
}
);
//here also tried to call api
}
ngOnInit() {
//here also tried to call api
}
ionViewDidLoad() {
console.log("calling api");
/*from with nginit*/
this.wooApi.getAsync('products/categories?parent=0').then((data) => {
console.log("success");
this.wooCat = JSON.parse(data.body);
//this.information = this.wooCat;
for (let i = 0; i < this.wooCat.length; i++) {
console.log("in for loop");
this.wooApi.getAsync('products/categories?parent=' + this.wooCat[i].id).then((data) => {
console.log("get success", i);
let wooChild = JSON.parse(data.body);
for (let x = 0; x < wooChild.length; x++) {
this.infoChild.push(wooChild[x]['name']);
}
//console.log(this.infoChild)
this.information.push({
'items': {
'name': this.wooCat[i]['name'],
'children': [{
'name': this.infoChild
}]
}
});
this.infoChild = [];
});
}
console.log("current data", this.information);
});
}
}
나는 ** ngOnInit() & ionViewDidLoad() ** 데이터가 제대로 점점하지만 내보기/HTML 페이지에 반영되지와도) 생성자 (와을 API를 호출하기 위해 노력했다.
<accordion *ngFor="let catParent of information" [title]="catParent.items.name">
<!-- (click)="itemSelected(item)" -->
<ion-list *ngFor="let catChild of catParent.items.children">
<button ion-item *ngFor="let catChildName of catChild.name">
{{ catChildName }}
</button>
</ion-list>
</accordion>
을 내가 카테고리 탭 API를 클릭하면 내가 다른 클릭하면 지금, 내보기 페이지에서이 결과를 볼 수 호출 및 응답을 얻는 것이 아니라 다음과 같이
내 HTML 코드입니다 탭을 다시 클릭하고 카테고리 탭을 클릭하면이 데이터를 볼 수 있습니다.
저는 이온 2를 처음 사용하기 때문에이 문제를 해결할 수 없습니다. 누구든지이 문제를 해결할 수 있습니까? 사전 :