【问题标题】:New to Ionic: Typescript Error in App.Component.TsIonic 新手:App.Component.Ts 中的 Typescript 错误
【发布时间】:2018-03-22 03:34:40
【问题描述】:

我的 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 还很陌生,我主要是按照指南开始。任何关于此事的建议将不胜感激。这是我收到的错误消息:

Error Message

【问题讨论】:

    标签: angular typescript ionic2 ionic3


    【解决方案1】:

    使用Angular在构造函数中注入的实例(DI),而不是StatusBarSplashScreen类的静态方法,如下所示:

    initializeApp() {
        this.platform.ready().then(() => {
            this.statusBar.styleDefault();
            this.splashScreen.hide();
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-16
      • 2018-02-12
      • 1970-01-01
      • 2019-10-05
      • 1970-01-01
      • 2018-03-14
      • 1970-01-01
      • 2017-03-08
      相关资源
      最近更新 更多