Im making a To Do App where it gets the Task from file B and then display it to file A, the problem is that I cant push an array from B to A and here is the error. Im still new to programming so please go easy on me...
here is the code :
src/pages/addtask/addtask.ts
import { Component } from '@angular/core'; import { NavController, IonicPage, NavParams } from 'ionic-angular'; import { HomePage } from '../home/home'; import { Storage } from '@ionic/storage' @Component({ selector: 'page-task', templateUrl: 'addtask.html' }) export class AddTask { // from here tasks = [] post(){ this.tasks.push(this.tasks); this.HomePage.avtasks.push(this.tasks); } constructor(public navCtrl: NavController, private storage: Storage, public HomePage) { } close(){ this.navCtrl.pop(); } }
src/pages/home/home.ts
import { Component } from '@angular/core'; import { NavController, IonicPage, NavParams } from 'ionic-angular'; import { AddTask } from '../addtask/addtask' import { Storage } from '@ionic/storage'; @Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage { // to here avtasks:any[] = [] constructor(public navCtrl: NavController, private storage: Storage) { } openCT(){ this.navCtrl.push(AddTask); } }
Thanks in advance!
HomePage
is a class, not an instance . So what you want to do probably is to communicate between the two page instances.
My suggestion is to create a singleton service which contains the data you want to share.
Maybe this post would help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.