NullInjectorError: No provider for NavController

2019-07-27 08:47发布

I want to navigate on each side menu items in a click event.

app.html

<ion-menu [content]="content">
    <ion-header>
      <ion-toolbar>
        <ion-title>Pages</ion-title>
      </ion-toolbar>
    </ion-header>

    <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 #content [root]="rootPage"></ion-nav>

app.component.ts

rootPage = FirstRunPage;
@ViewChild('content') nav: NavController
  controller()  {
  }

 openPage(page) {
 this.nav.setRoot(page.component);
  }

I have imported import { Platform, NavController, Nav } from 'ionic-angular'; But shows error message

NullInjectorError: No provider for NavController! enter image description here

0条回答
登录 后发表回答