zoukankan      html  css  js  c++  java
  • ionic3 使用LoadingController时需要多次加载模态框时模态框关闭不了的问题

    我们做ajax请求时会经常使用模态框阻止用户进行下一步的操作,例如显示 ‘正在加载...’
    当我们同时请求多个接口时多次创建模态框 并每次请求成功时关闭自己的模态框,理论上是没有问题的,因为每次请求都创建自己的模态框对象,互不影响,但是当你关闭时确实有问题
    可能自己对ionic3理解不够
    export class HttpService {
      loadingIsOpen:any;
      loading:any;
      constructor(public http: Httpprivate loadingCtrl: LoadingController) {
      
      }
      private showLoading(content: any = ''): void {
      if(typeof content != 'string'){
      content = '';
      }
      if (!this.loadingIsOpen) {
      this.loadingIsOpen = true;
      this.loading = this.loadingCtrl.create({
      content: content
      });
      this.loading.present();
      setTimeout(() => { //最长显示10秒
      this.loadingIsOpen && this.loading.dismiss();
      this.loadingIsOpen = false;
      }, 10000);
      }else{
      this.loading.setContent(content);
      }
      };
      private hideLoading(): void {
      this.loadingIsOpen && this.loading.dismiss();
      this.loadingIsOpen = false;
      };
    }
    这段代码是全局创建唯一的模态框对象  用loadingIsOpen去记录目前是否有模态框(因为返回的loading 对象没有属性标示当前模态框状态,你也可以检索html是否ion-loading标签去判断)这样,大家公用一个模态框关闭就不会有问题了。
    个人感觉ionic只允许一个时间点创建一个loading;
    多次创建关闭时就找不到相应的模态框,也就会造成关闭不了的情况
    大家可以深入研究下

    后来有时间研究了下请移驾这个网址:https://blog.csdn.net/rui_code/article/details/81940036


  • 相关阅读:
    composer 中国全量镜像 laravel-china.org
    Increase PHP script execution time with Nginx
    How to make a USB stick use ISO image file in debian
    Getting svn to ignore files and directories
    Carbon document
    Use Laravel/homestead 环境维护基于 brophp 开发的老项目
    Vagrant WinNFSd
    How to use jQuery countdown plugin
    消息系统的设计与实现
    VMvare 复制的数据库,需要改变的配置
  • 原文地址:https://www.cnblogs.com/rui00910/p/8136900.html
Copyright © 2011-2022 走看看