0

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...

from ionic serve --lab

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!

Abhishta Gatya
  • 883
  • 2
  • 14
  • 32

1 Answers1

0

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.

awmleer
  • 1,658
  • 3
  • 13
  • 28
  • okay, so do you have any suggestions that could make this work? maybe a completely different method but same results? – Abhishta Gatya Aug 13 '17 at 06:38
  • Actually there is an example in Angular's official document, I think you'd better read it first: https://angular.io/guide/component-interaction#parent-and-children-communicate-via-a-service – awmleer Aug 13 '17 at 06:45