이온 2/각도 2 앱에 문제가 있습니다.이온 2 : 예외 : NavController 제공 업체 없음
"auth"부분이 구현 된 app.ts가 있습니다.
코드는 다음과 같습니다
ORIGINAL EXCEPTION: No provider for NavController
어떻게이 문제를 해결하기 위해 어떤 생각을 가지고 있습니까 :
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);
}
}
하지만 지금이 응용 프로그램을 실행하려고 할 때, 나는이 메시지가? 감사!
이것은 오류가 아닙니다. 'NavController' 제대로 가져 왔습니다. 문제는 여기에 주입 할 수 없다는 것입니다. 그는 @ViewChild (Nav) nav : Nav;를 작성하여'nav'에 대한 참조를 만들었습니다. 'Nav'는'NavController'를 확장하여 대신 사용할 수 있습니다. –