I am facing an issue with displaying the data received from NavParams
. I have used console.log()
to confirm that I am getting the correct data, but for some reason, I am unable to display it on the new page.
I suspect that there might be an error in how I passed the data, but I am unsure of what mistake I made.
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 obtained
this.newEntry({ record: results }); //Potential 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")); //Returns NULL
}
locations.ts
//function to retrieve 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);
});
});
}