Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No provider for NavController

i started an ionic 2 app from the sidemenu starter. Now i want to move the code generated into the app component (the menu) into a folder and write a home component instead. When i run the app it shows me this error:

ORIGINAL EXCEPTION: No provider for NavController!

The code for my app.component is:

import { Component } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';
import { StatusBar } from 'ionic-native';

import { Login } from '../pages/login/login';

@Component({
  templateUrl: 'app.html'
})
export class MyApp {

  nav: NavController;

  constructor(public platform: Platform, nav: NavController) {
    this.nav = nav;
    this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      StatusBar.styleDefault();
    });
  }

  registerUserWithFacebook(){
    console.log('Facebook');
    //this.nav.setRoot(pantryList);
  }

  registerUserWithGoogle() {
    console.log('Google');
    //this.nav.setRoot(pantryList);
  }

  openSignUpPage(){
    console.log('Signup');
    //this.nav.setRoot(Signup);
  }

  openLoginPage(){
    console.log('Login');
    this.nav.push(Login);
  }

  openTermsOfService(){
    console.log('Terms of service');
  }
}

And i want to redirect to my menu (sidemenu) page:

import {Component} from "@angular/core";
import { NavController } from 'ionic-angular';

import { pantryList } from '../pantryList/pantryList';

@Component({
    templateUrl: "login.html"
})
export class Login {

    email: string;
    password: string;

    constructor(public navCtrl: NavController) {
    }

   onLogin() {
      this.navCtrl.setRoot(pantryList);
   }    
}
like image 590
Fernando Del Olmo Avatar asked Oct 19 '16 12:10

Fernando Del Olmo


1 Answers

Forced that thing to work in next way

  constructor(
    protected app: App
  ) {

...

  get navCtrl(): NavController {
    return this.app.getActiveNav();
  }
like image 140
Vladimir Tolstikov Avatar answered Sep 30 '22 18:09

Vladimir Tolstikov