Ionic 4: “Loading Controller” dismiss() is called before present() which will keep spinner without dismissing

前端 未结 20 2279
逝去的感伤
逝去的感伤 2020-12-08 01:06

I used \"Ionic Loading Controller\" to show a spinner until the data is retrieved then it calls \"dismiss()\" to dismissed it. it works fine, but sometimes when the app alre

20条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 01:33

    I had the same problem, apparently I figured It out by identifying the problem first. This problem occurs when the duration of that Loader got expired so it basically got dismissed without our full control..

    Now, It will work fine Until you are also using dismiss() MANUALLY.

    So if you are going to use dismiss() manually with duration, remove the duration on create. then use setTimeout() perhaps

    // create loader
    this.loader = this.loadingCtrl.create()
    
    // show loader
    this.loader.present().then(() => {})
    
    // add duration here
    this.loaderTimeout = setTimeout(() => {
        this.hideLoader()
    }, 10000)
    

    then create your hide loader here

    // prepare to hide loader manually
    hideLoader() {
       if (this.loader != null) {
          this.loader.dismiss();
          this.loader = null
        }
    
        // cancel any timeout of the current loader
        if (this.loaderTimeout) {
          clearTimeout(this.loaderTimeout)
          this.loaderTimeout = null
        }
    }
    

提交回复
热议问题