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

Sign up to request clarification or add additional context in comments.

1 Comment

thank you for pointing me in the right direction this is what i needed.
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');
      }

    }

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.