首页 > 解决方案 > ionic4 App - 登陆页面在启动期间加载控制器页面之前显示几毫秒

问题描述

我想在登陆页面之前显示加载页面几秒钟,是的,我已经使用ionic4中的加载控制器实现了它,同时登陆页面在登陆页面之前出现了第二个分割,我尝试了很多调用加载功能的选项在不同的地方,但没有任何效果。下面是 app.component.ts 文件。请帮忙。

export class AppComponent {
       constructor(
        private platform: Platform,
        private splashScreen: SplashScreen,
        private statusBar: StatusBar,
        private loadingController: LoadingController
      ) { 
        this.presentLoadingWithOptions();   
        this.initializeApp(); 
      }


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

        });
      }

       async presentLoadingWithOptions() {
        const loading = await this.loadingController.create({
          spinner: null,
          duration: 8000,
          message:' Relax Take a Deep Breath ' ,
          translucent: true,
          cssClass: 'custom-class custom-loading'
        });
        return await loading.present();
      }

标签: ionic4

解决方案


请记住,每个异步函数都返回一个 Promise 对象。

在调用之前,您应该等待加载控制器关闭initializeApp

我会改写成这样的:

export class AppComponent {
  constructor(
  private platform: Platform,
  private splashScreen: SplashScreen,
  private statusBar: StatusBar,
  private loadingController: LoadingController
) { 
  this.presentLoadingWithOptions()
    .then(() => this.initializeApp());
}

initializeApp() {
  ...
}

async presentLoadingWithOptions() {
  const loading = await this.loadingController.create({
    spinner: null,
    duration: 8000,
    message:' Relax Take a Deep Breath ' ,
    translucent: true,
    cssClass: 'custom-class custom-loading'
  });
  loading.present();
  return await loading.onDidDismiss(); // Will resolve after 8000ms
}

推荐阅读