Ich habe ein Problem mit meiner ionic 2/angular 2 App.Ionic 2: AUSNAHME: Kein Provider für NavController
Ich habe eine App.ts, wo das Loch "Auth" Teil implementiert ist.
Der Code sieht wie folgt aus:
import {Nav, Platform, Modal, ionicBootstrap} from "ionic-angular";
import {NavController} from "ionic-angular/index";
import {StatusBar} from "ionic-native";
import {Component, ViewChild} from "@angular/core";
import {AngularFire, FirebaseListObservable, FIREBASE_PROVIDERS, defaultFirebase} from "angularfire2";
import {HomePage} from "./pages/home/home";
import {AuthPage} from "./pages/auth/home/home";
@Component({
templateUrl: "build/app.html",
})
class MyApp {
@ViewChild(Nav) nav: Nav;
authInfo: any;
rootPage: any = HomePage;
pages: Array<{title: string, component: any}>;
constructor(private platform: Platform, private navCtrl: NavController, private af: AngularFire) {
this.initializeApp();
this.pages = [
{ title: "Home", component: HomePage }
];
}
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();
});
}
openPage(page) {
this.nav.setRoot(page.component);
}
ngOnInit() {
this.af.auth.subscribe(data => {
if (data) {
this.authInfo = data;
} else {
this.authInfo = null;
this.showLoginModal();
}
});
}
logout() {
if (this.authInfo) {
this.af.auth.logout();
return;
}
}
showLoginModal() {
let loginPage = Modal.create(AuthPage);
this.navCtrl.present(loginPage);
}
}
Aber jetzt, wenn ich versuche, die app ich diese Nachricht erhalten laufen:
ORIGINAL EXCEPTION: No provider for NavController
Haben Sie eine Ahnung, wie dieses Problem zu lösen? Vielen Dank!
Dies ist kein Fehler! 'NavController' wird korrekt importiert. Das Problem ist, dass es hier nicht injiziert werden kann. Er bezog sich auf 'nav', indem er' @ViewChild (Nav) nav: Nav; 'schrieb. 'Nav' erweitert' NavController' und kann stattdessen verwendet werden. –