Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic3 NullInjectorError: No provider for NavController

I'm getting the error NullInjectorError: No provider for NavController. I searched for it and I know I shouldn't inject it into the appcomponent. I'm not doing so, but I still get the error. I have appComponent which is my rootcomponent. As startpage i'm setting my StartPage. In this StartPage i'm injecting the What am I doing wrong?

AppComponent template:

<ion-nav #content [root]="rootPage"></ion-nav>

AppComponent:

export class AppComponent {
    rootPage: any = StartPage; //Setting my start page

    constructor(
        private platform: Platform,
        private statusBar: StatusBar,
        private splashScreen: SplashScreen) {
    }

    ionViewDidLoad() {
        this.platform.ready().then(() => {
            this.statusBar.styleBlackTranslucent();
            this.splashScreen.hide();
        });

    } 
}

StartPage:

export class StartPage {
    constructor(private navController: NavController){

    }

    signin(){
        this.navController.push(LoginPage);
    }

    signup(){
        this.navController.push(SignupPage);
    }

}
like image 414
Robin Dijkhof Avatar asked Feb 01 '26 23:02

Robin Dijkhof


1 Answers

Try to import NavCtrl at the top of the file, where you need it (at the top of the StartPage?):

import { NavController } from 'ionic-angular';

And adding it into constructor, as you did, should be enough.

like image 134
cssBlaster21895 Avatar answered Feb 04 '26 00:02

cssBlaster21895