Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49425

Ionic2 - unable to retrieve/display data using navcontroller

$
0
0

@chenjian wrote:

I am unable to display the data I get from NavParams. I use console.log() and check that I did get the data I wanted but unable to display in the new page.

I think I might had make some mistake during the passing of data, but not sure what did i do wrong.

Any help is appreciated. Thanks in advanced.

first.ts

import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { LocationsProvider } from '../../providers/locations/locations';

 constructor(
 public locations: LocationsProvider,
 public viewCtrl: ViewController,
 public navCtrl: NavController,
 public actionSheetCtrl: ActionSheetController,
 public http: Http,
 public navParams: NavParams,
 ) {
 }

   newEntry(param){
    this.navCtrl.push('SecondPage',param);
}


    openActSheetjob_Type(){

    let actionsheet = this.actionSheetCtrl.create({

    title:"Type",
    buttons:[
        {
    text: 'Hour',
    handler: () => {

              let Hourly = "Hourly";
              let results =  this.locations.getData(Hourly);

              console.log(results); // data goten

            this.newEntry({ record: results });   //Suspect mistake
          }
      }
   ]
 });
 actionsheetjob_type.present();
}

Second.html

<ion-list >

<ion-item *ngFor="let list of this.results">

  <h2>{{ list.Title }}</h2>
  <p>{{ list.Type }}</p>
  </ion-item>

</ion-list>

Second.Ts

     ionViewDidLoad(){
      console.log(this.NP.get("record")); //Get NULL
    }

locations.ts

 //function to get data
 data:any;

getData(jobType){

 if (this.data) {

  return Promise.resolve(this.data);
 }

  return new Promise(resolve => {

  this.http.get('http://localhost/getType.php?Type=' + Type)
  .map(res => res.json())
  .subscribe(data => {

    this.data = data;
    console.log(this.data);

    resolve(this.data);
  });

});

}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49425

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>