我是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文件的代码部分,现在我想使用参数将数据传递到下一页。我想知道应该传入什么参数才能在下一页显示数据
答案 0 :(得分:0)
根据您的代码,您正在将ID直接传递给服务的import numpy as np
import matplotlib.pyplot as plt
import csv
with open('titanic_data.csv') as file:
reader = csv.reader(file)
#Creates an empty list called ages, to be populated with our age data
gender = []
survived = []
boysurvive = []
girlsurvive = []
count = 0
#loops throughpopulates our ages list with age data from titanic_data.csv
for column in reader:
gender.append(column[2])
survived.append(column[0])
gender.pop(0)
survived.pop(0)
for item in gender:
if gender[count] == '1' and survived[count] == '1':
girlsurvive.append(1)
elif gender[count] == '1' and survived[count] == '0':
girlsurvive.append(0)
elif gender[count] == '0' and survived[count] == '1':
boysurvive.append(1)
elif gender[count] == '0' and survived[count] == '0':
boysurvive.append(0)
count = count + 1
range = [0,1]
#Doesn't work
#plt.scatter(range, girlsurvive)
#plt.scatter(range, boysurvive)
plt.show()
方法。因此,请使用getCategoryPosts
代替category
,如下所示。
category.id