Hello,
I’m trying to create an array to store each post ID, here’s my .ts:
private url: string = "https://api.myjson.com/bins/1as3cr";
public ids: Array <any>;
public names: Array <any>;
constructor(public navCtrl: NavController, public http: Http, public loadingCtrl: LoadingController, public navParams: NavParams, public storage: Storage) {
this.fetchContent();
}
fetchContent ():void {
let loading = this.loadingCtrl.create({
content: 'Buscando categorias...'
});
loading.present();
this.http.get(this.url).map(res => res.json())
.subscribe(data => {
this.ids = data.data;
loading.dismiss();
this.createCategories ();
});
}
createCategories (){
for (let entry in this.ids){
alert (JSON.stringify(this.ids));
}
}
The alert is printing something like:
[{"term_id":3,"name":"Cultura","slug":"cultura","term_group":0,"term_taxonomy_id":3,"taxonomy":"category","description":"","parent":0,"count":1,"filter":"raw","cat_ID":3,"category_count":1,"category_description":"","cat_name":"Cultura","category_nicename":"cultura","category_parent":0},{"term_id":4,"name":"Política","slug":"politica","term_group":0,"term_taxonomy_id":4,"taxonomy":"category","description":"","parent":0,"count":2,"filter":"raw","cat_ID":4,"category_count":2,"category_description":"","cat_name":"Política","category_nicename":"politica","category_parent":0}]
What I’m trying to do is store only the “name”. I already tried this:
createCategories (){
for (let entry in this.ids){
alert (JSON.stringify(this.ids["name"]));
}
}
But that returns: undefined.
How can I print, and store (later) the “name” attribute in this.ids?
Thank you!