Ionic framework 在ionic 3中传递api的参数
我是新来的离子和试图通过api从供应商的应用程序的ts页面,但我得到了一个错误,也许我传递了错误的id TS部分:Ionic framework 在ionic 3中传递api的参数,ionic-framework,ionic3,Ionic Framework,Ionic3,我是新来的离子和试图通过api从供应商的应用程序的ts页面,但我得到了一个错误,也许我传递了错误的id TS部分: export class CardsPage { currentItems: Item[]; id: any; getData: Object; categories; constructor(public navCtrl: NavController, public api:Api, navParams: NavParams,
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:
我已经发布了关于API和ts文件的代码部分,现在我想使用参数将数据传递到下一页。我想知道我应该传递什么参数来获取下一页中显示的数据根据您的代码,您正在将id直接传递给服务的
getCategoryPosts
方法。因此,请使用category
而不是下面的category.id
getCategoryPosts(category: any) {
return this.http.get(`${this.api_url}/posts?categories=${category}`);
}
请发布错误的副本。引用错误:未定义类别引用错误。在新卡上未定义类别SPAGEI仍然收到此错误:-引用错误:未定义类别引用错误。新卡片页未定义类别。
getCategoryPosts(category: any) {
return this.http.get(`${this.api_url}/posts?categories=${category}`);
}