How to transfer data to ionic2

I get data via http. I want to pass data to PlacesListPage. My data has "id, name, category, ...". I want to use the thesis in PlacesListPage as follows: {{xxx.id}}, {{xxx.name}} ... Please help me ... xxx - for example)

import {Page, NavController, NavParams} from 'ionic-angular';
import {Http} from 'angular2/http';
import 'rxjs/Rx';
import {PlacesListPage} from '../places-list/places-list';
/*enter code here
  Generated class for the PlacesPage page.

  See http://ionicframework.com/docs/v2/components/#navigation for more info on
  Ionic pages and navigation.
*/
@Page({
  templateUrl: 'build/pages/places/places.html',
})
export class PlacesPage {
  static get parameters() {
    return [[NavController], [Http], [NavParams]];
  }


  constructor(nav, http, navParams) {
    this.nav = nav;
    this.http = http.get('https://api.myjson.com/bins/2ud24').map(res => res.json()).subscribe(
        (data) => {
          this.data = data;
        });

}
+4
source share
2 answers

You can also use this approach:

let something = { test: 1 };
this.nav.push(existingPaymentModal, {something});

and than

constructor(private navParams: NavParams) {
        this.something = this.navParams.get("something");
 }
+7
source

Use the NavController to transfer data to the page when you go to it:

this.nav.push(PlacesListPage, {
    xxx: this.data
});

Then use NavParams in your PlacesListPage to access the data:

constructor(navParams) {
    this.xxx = navParams.data.xxx;
}

http://ionicframework.com/docs/v2/api/components/nav/NavParams/

+2
source

All Articles