【发布时间】:2019-01-30 13:11:48
【问题描述】:
我是 Ionic 的新手,并试图将 api 从提供程序传递到应用程序的 ts 页面,但我收到了一个错误,可能是我传递了错误的 id。
TS部分:
export class CardsPage {
currentItems: Item[];
id: any;
getData: Object;
categories;
constructor(public navCtrl: NavController, public api:Api, navParams:
NavParams, items: Items, public http: HttpClient) {
this.id = navParams.get('idName') ||'';
console.log(this.id);
this.api.getCategoryPosts(this.id).subscribe(data=>{
console.log(data)
this.getData = data
},err=>{
console.log(err)
})
}
openItem(item){
this.navCtrl.push('ItemDetailPage', {
itemName: item
});
}
}
API:
getCategoryPosts(category: any) {
return this.http.get(`${this.api_url}/posts?categories=${category.id}`);
}
我已经发布了关于我的 API 和 ts 文件的代码部分,现在我想使用参数将数据传递到下一页。我想知道我应该传递什么参数来获取下一页显示的数据
【问题讨论】:
-
请发布错误的副本。
-
参考错误:类别未定义参考错误。新 CardsPage 中未定义类别