I am a newcomer to Ionic 2 and I am encountering difficulties when it comes to passing data between pages. Within my Home.ts file, there exists a global array containing certain numbers that have been calculated. My intention is to transfer this array to my Table.ts file in order to display it within an HTML table using the *ngFor method.
Below is the function within Home.ts where I populate the array and attempt to push (I will omit the actual calculations since I am confident they are accurate).
import { Component } from '@angular/core';
import { AlertController } from 'ionic-angular';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Table } from '../table/table';
export class HomePage {
averagesList: Array<number> = [];
constructor(public alerCtrl: AlertController,
public navCtrl: NavController,
public navParams: NavParams) {}
Calculate() {
var Averages = [];
// Calculations on the 'Averages' Array
this.averagesList = Averages;
this.navCtrl.push(Table, this.averagesList);
}
}
When attempting to display this data in my Table.ts file, I receive an undefined result.
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { HomePage } from '../home/home';
@IonicPage()
@Component({
selector: 'page-table',
templateUrl: 'table.html',
})
export class Table{
constructor(public navCtrl: NavController, public navParams: NavParams) {}
ionViewDidLoad() {
console.log(this.navParams.get('averagesList'));
}
}
I have experimented with passing a let variable which was successful, so why does it not function as expected with arrays?