【问题标题】:Passing parameters from api in ionic 3从 ionic 3 中的 api 传递参数
【发布时间】: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 中未定义类别

标签: ionic-framework ionic3


【解决方案1】:

根据您的代码,您将 id 直接传递给服务的 getCategoryPosts 方法。因此使用category 而不是category.id,如下所示。

getCategoryPosts(category: any) {
      return this.http.get(`${this.api_url}/posts?categories=${category}`);
  }

【讨论】:

  • 我仍然收到此错误:: - 参考错误:未定义类别参考错误。新 CardsPage 中未定义类别。
猜你喜欢
  • 1970-01-01
  • 2018-02-17
  • 1970-01-01
  • 2022-11-10
  • 1970-01-01
  • 1970-01-01
  • 2017-03-12
  • 2019-03-15
  • 1970-01-01
相关资源
最近更新 更多