0

Typescript get failed to find exported component,May be exported module not appropriatly imported into other component.

It show an error message while call AddToArray method:

Cannot read property 'push' of undefined

PageOne.ts

var const array = new Array(5);
export array;
class PageOne {
  constructor(public navCtrl: NavController, public navParams: NavParams) {
  }   
  GoToPage(){
    this.navCtrl.push('PageTwo');
  } 
}

PageTwo.ts

import { players } from  '../pageone/pageone.ts'

export class PlayersPage {
  constructor(public navCtrl: NavController, public navParams: NavParams) { }
  AddToArray(){
     array.push("TEST") 
  }
}

2 Answers 2

2

In fact, I do not understand why you use the array and export it. I guess if you just want to make some data type to save and share the data among components.

I would say to use service since each component calls the service to set or get the data from the service.

This doc would be helpful https://angular.io/tutorial/toh-pt4#why-services

1
  • thank you for pointing me in the right direction this is what i needed.
    – jrocc
    Commented Mar 15, 2018 at 2:55
0

You're getting the error because you must declare and initialize the array before using it.

    class PageOne {
      let navCtrl: string[] =[];

      constructor(public navCtrl: NavController, public navParams: NavParams) {
      }

      GoToPage(){
        this.navCtrl.push('PageTwo');
      }

    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.