我正尝试将导航添加到我的Ionic 2应用程序中的app.component.ts
文件。出于某种原因,我收到一个错误,nav
未定义。Ionic 2 - Nav undefined
添加NavController
也是没有选择的,因为它会说没有供应商NavController
。
我收到错误(S)是:
Native: tried calling Facebook.browserInit, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator main.js (416,9)
Angular is running in the development mode. Call enableProdMode() to enable the production mode. main.js (3511,5)
Native: tried calling NativeStorage.getItem, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator main.js (416,9)
Native: tried calling StatusBar.styleDefault, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator main.js (416,9)
EXCEPTION: Uncaught (in promise):
TypeError: Unable to get property 'nav' of undefined or null reference TypeError: Unable to get property 'nav' of undefined or null reference
at Anonymous function (http://localhost:8100/build/main.js:125439:17)
at t.prototype.invoke (http://localhost:8100/build/polyfills.js:3:9569)
at onInvoke (http://localhost:8100/build/main.js:38701:21)
at t.prototype.invoke (http://localhost:8100/build/polyfills.js:3:9569)
at e.prototype.run (http://localhost:8100/build/polyfills.js:3:6993)
at Anonymous function (http://localhost:8100/build/polyfills.js:3:4652)
at t.prototype.invokeTask (http://localhost:8100/build/polyfills.js:3:10175)
at onInvokeTask (http://localhost:8100/build/main.js:38692:21)
at t.prototype.invokeTask (http://localhost:8100/build/polyfills.js:3:10175)
at e.prototype.runTask (http://localhost:8100/build/polyfills.js:3:7611)
at i (http://localhost:8100/build/polyfills.js:3:3700)
at invoke (http://localhost:8100/build/polyfills.js:3:11431)
main.js (78327,9)
ORIGINAL STACKTRACE: main.js (78332,13)
Error: Uncaught (in promise):
TypeError: Unable to get property 'nav' of undefined or null reference
TypeError: Unable to get property 'nav' of undefined or null reference at Anonymous function (http://localhost:8100/build/main.js:125439:17)
at t.prototype.invoke (http://localhost:8100/build/polyfills.js:3:9569)
at onInvoke (http://localhost:8100/build/main.js:38701:21)
at t.prototype.invoke (http://localhost:8100/build/polyfills.js:3:9569)
at e.prototype.run (http://localhost:8100/build/polyfills.js:3:6993)
at Anonymous function (http://localhost:8100/build/polyfills.js:3:4652)
at t.prototype.invokeTask (http://localhost:8100/build/polyfills.js:3:10175)
at onInvokeTask (http://localhost:8100/build/main.js:38692:21)
at t.prototype.invokeTask (http://localhost:8100/build/polyfills.js:3:10175)
at e.prototype.runTask (http://localhost:8100/build/polyfills.js:3:7611)
at i (http://localhost:8100/build/polyfills.js:3:3700)
at invoke (http://localhost:8100/build/polyfills.js:3:11431)
at v (http://localhost:8100/build/polyfills.js:3:4856)
at s (http://localhost:8100/build/polyfills.js:3:4283)
at Anonymous function (http://localhost:8100/build/polyfills.js:3:4690)
at t.prototype.invokeTask (http://localhost:8100/build/polyfills.js:3:10175)
at onInvokeTask (http://localhost:8100/build/main.js:38692:21)
at t.prototype.invokeTask (http://localhost:8100/build/polyfills.js:3:10175)
at e.prototype.runTask (http://localhost:8100/build/polyfills.js:3:7611)
at i (http://localhost:8100/build/polyfills.js:3:3700)
at invoke (http://localhost:8100/build/polyfills.js:3:11431)
main.js (78333,13)
我正在使用的代码:
import { Component, ViewChild } from '@angular/core';
import { Nav, Platform } from 'ionic-angular';
import { StatusBar, Splashscreen, NativeStorage, Facebook } from 'ionic-native';
import { HomePage } from '../pages/home/home';
import { LoginPage } from '../pages/login/login';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage = LoginPage;
constructor(private platform: Platform) {
this.InitliazeApp();
}
InitliazeApp() {
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.
NativeStorage.getItem('user')
.then(function (data) {
this.nav.setRoot(HomePage);
Splashscreen.hide();
}, function (error) {
this.nav.setRoot(LoginPage);
Splashscreen.hide();
});
StatusBar.styleDefault();
});
}
}
添加提供程序在ngModules –
@varunaaruru我使用Angular2在我的项目,我应该添加这个的任何想法?通过在我的'app.module.ts'中添加NavController,我收到了很多错误,所以这可能不是它。 – Peurr
你可以显示html端吗? –