D.D
D.D

Reputation: 31

ionic 2 sidemenu - pass nav from app.ts to menu component

I need to implement a logic same as given in the below link: ionic 2 sidemenu - navCtrl inside a component

I have ion-nav in app.ts & within the app.html there is another custom component(menu.ts). From inside the menu.ts, I want to navigate/set another component as root

I am getting error Cannot read property 'setRoot' of undefined

How can I pass nav from app.ts to the menu component?

Upvotes: 0

Views: 663

Answers (1)

cherry-wave
cherry-wave

Reputation: 731

You can pass parameters to pages like this:

app.ts

this.nav.setRoot(page.component, nav);

and afterwards read them with:

page.ts

constructor(public params: NavParams) {
    this.nav= params.get('nav');
}

But this shouldn't be necessary when you want to call "setRoot" I do it like this:

page.ts

constructor(public navCtrl: NavController) {
} 

....

navigateToPage() {
    this.navCtrl.setRoot(Page);
}

Upvotes: 0

Related Questions