ionic4 - 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();
}
解决方案
请记住,每个异步函数都返回一个 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
}
推荐阅读
- android - 在 Android Q 中从 SD 卡生成缩略图
- android - 什么是Impl文件,在什么条件下会自动生成Impl文件?
- python - KeyError:'无法找到名为 app 的无状态 DjangoApp'
- python - 无法在 anaconda 中安装 pal2nal 软件包
- sql - 如果 Oracle SQL 列中的数字是完整的整数,则添加两个带小数的零
- python - 使用 python 绘制 2D 步行
- javascript - 尝试将组件名称从字符串转换为 Angular 9 中的组件类型会导致传入的类型不是 ComponentType 错误
- c# - 想要使用 c# 在浏览器中连接到 Azure Windows 虚拟桌面?
- excel - csv 中的换行符导入 Excel
- asp.net-mvc - 是否有任何选项可以使用 ASP.NET Core 3.1 打开浏览器的“下载前询问每个文件的保存位置”?