我在Ionic应用程序中遇到TypeScript错误。我有一个sidemenu应用程序,并将菜单分成它自己的组件,以便我可以更容易地添加登录页面。我一直在遵循本指南:http://roblouie.com/article/344/ionic-2-hide-menu-or-tabs-for-login-screen/
在我的新app.component.ts中,我有以下代码:
import { Component, ViewChild } from '@angular/core';
import { Nav, Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { MenuComponent } from "./menu.component";
@Component({
template: '<ion-nav #baseNav></ion-nav>'
})
export class MyApp {
@ViewChild('baseNav') nav: Nav;
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen) {
this.initializeApp();
}
ngOnInit() {
this.nav.push(MenuComponent, { animate: false });
}
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();
SplashScreen.hide();
});
}
}
我对Ionic很新,而且我一直都是按照指南开始的。对此事的任何建议将不胜感激。以下是我收到的错误消息:
答案 0 :(得分:3)
使用Angular在构造函数(DI
)中注入的实例,而不是StatusBar
和SplashScreen
类的静态方法,如下所示:
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}