gpt4 book ai didi

angular - 没有 NavController 的提供者

转载 作者:太空狗 更新时间:2023-10-29 17:14:09 25 4
gpt4 key购买 nike

我从侧边菜单启动器启动了一个 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');
}
}

我想重定向到我的菜单 (sidemenu) 页面:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com