我从sidemenu启动程序启动了ionic 2应用程序。现在,我想将生成到应用程序组件(菜单)中的代码移动到文件夹中,并编写一个家庭组件。当我运行该应用程序时,它向我显示此错误:
原来的异常(exception):NavController没有提供者!
我的app.component的代码是:
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');
}
}
我想重定向到我的菜单(边菜单)页面:
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);
}
}
最佳答案
强制该东西以另一种方式工作
constructor(
protected app: App
) {
...
get navCtrl(): NavController {
return this.app.getActiveNav();
}
关于angular - 没有NavController的提供者,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40131832/