angular - Ionic 4 加载符号在 observable 解析之前消失
问题描述
在导航到主屏幕之前,我几乎没有运行异步任务。我在启动这些任务之前启动了一个加载微调器,并在 ionViewWillLeave() 方法中关闭了加载微调器。
我的期望是,随着这些异步任务完成执行,加载微调器会继续加载,一旦完成,加载微调器只能从 ionViewWillLeave 方法中解除。
我当前的代码如下所示:
export class MyComponent implements OnInit{
ngOnInit(){}
buttonClicked(){
this.ionLoadingService.present();
zip(Obs1, Obs2).pipe(switchMap(()=>Obs3))
.subscribe(()=>{navigate('/app/home')});
}
ionViewWillLeave(){
this.ionLoadingService.dismiss();
}
}
export class IonLoadingService {
public loadingElement: HTMLIonLoadingElement;
private loaderPresented: boolean = false;
constructor(private loadingController: LoadingController) {
}
async present() {
if (!this.loaderPresented) {
this.loaderPresented = true;
this.loadingElement = await this.loadingController.create({
cssClass: 'custom-loading'
});
return await this.loadingElement.present();
}
}
注意:所有的 observables 都是在角度区域之外运行的 API 调用。加载微调器的当前行为是,一旦这些外部 observable 开始执行,它就会消失。
如何解决这个问题?
解决方案
推荐阅读
- r - 有没有办法在我们打开应用程序后立即自动点击 R 闪亮应用程序
- r - 为什么它没有给我最大的输出?
- c# - 如何识别在同一台计算机上始终具有相同 ID 的用户?
- python - 如何根据另一列中的值检索数据框列中的元素并将其存储在列表中
- django - 如何将我的两个 django 模型的特定字段相互链接?
- javascript - 自动化后如何重新渲染组件?
- database - Flask:查询结果未显示在使用 jinja 的网页上(user_data)
- android - 圆形图像视图:空指针异常
- javascript - 如何在没有按钮的情况下控制 React-Bootstrap Dropdown 的可见性?
- c++ - 将通用引用转换为可调用的 void 指针,反之亦然