I'm using the ionic 2 starter template with sidemenu.
So the original app.html looks like this
<ion-menu [content]="content">
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
<ion-content>
<ion-list>
<button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
</ion-content>
</ion-menu>
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
and I want to replace the menu content with a component like this
<ion-menu [content]="content">
<st-menu></st-menu>
</ion-menu>
my menu.component.ts looks like this, which is basically copied from the original app.ts file
import {Page1} from "../pages/page1/page1";
import {Page2} from "../pages/page2/page2";
import {Nav, NavController} from "ionic-angular";
@Component({
selector: 'st-menu',
templateUrl: 'build/menu/menu.html'
})
export class MenuCmp {
@ViewChild(Nav) nav: Nav;
pages: Array<{title: string, component: any}>;
constructor(private navCtrl:NavController) {
this.pages = [
{ title: 'Home', component: HomePage },
{ title: 'Page uno', component: Page1 },
{ title: 'Page dos', component: Page2 }
];
}
openPage(page) {
this.nav.setRoot(page.component);
}
}
and menu.html like this
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
<ion-list>
<button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
Now when I click inside the menu I've getting an error:
Cannot read property 'setRoot' of undefined
I've tested by replacing this.nav.setRoot(page.component) with this.nav.setRoot(HomePage); and it still the same. When I replace nav with navCtrl (provided and injected) it says this.navCtrl.setRoot is not a function
Any suggestions? Thanks!