Reference App Component

I’m try to get the reference to the App Component

import { App } from 'ionic-angular'; 

class AnotherComponent {
  constructor (private app: App) {
    
  }

  doStuff () {
    this.app.appRoot.someMethodDefinedInMyAppComponent()
  }
}

someMethodDefinedInMyAppComponent() doesn’t seem to be available according to my editor’s intelli-sense.

How can I get the reference to MyApp component?

What I do now

in MyApp component

ngOnInit() {
  window['appComponent'] = this;
}

foo() { ... }

in the other component

foo() {
  window['appComponent'].bar();
}

1 Like