LoadingController delay in Ionic 2

In Ionic 1 we used to have a “delay” property in $ionicloading, so the loading won’t get displayed if duration is less than delay value. I don’t see that property in LoadingController options of Ionic 2 docs. I’ve tried setting it but it doesn’t work. Any plans on adding it? Is there any workaround?
Thanks!

1 Like

I can’t say for sure, but I don’t think we’ll be adding this to LoadingController. It’s quite straight forward though to mimc the same behaviour.

presentLoadingDefault() {
  let loading = this.loadingCtrl.create({
    content: 'Please wait...'
  });

  loading.present();

  setTimeout(() => {
    loading.dismiss();
  }, 5000);
}

Hi @mhartington! Thanks for the quick response. I think what you’re trying to mimic with your sample is the duration behavior (how long does the loading controller is displayed and forced to be closed, if not closed yet).
What I’m trying to do is to delay the display. Eg: if my view loading time is less than a second, I don’t want to display the loading spinner. Setting the delay to 1000 in ionic 1 do that!

I believe the way to mimic that would be:

presentLoadingDefault() {
  let loading = this.loadingCtrl.create({
    content: 'Please wait...'
  });

  setTimeout(() => {
     loading.present();
  }, 1000);
}

Dismissal might be a bit tricky.

let loadingPresented = false;
let loadingTimer = setTimeout(() => {
  loading.present();
  loadingPresented = true;
}, 1000);

doHeavyOperation().then(() => {
  if (loadingPresented) {
    loading.dismiss();
  } else {
    clearTimeout(loadingTimer);
  }
});
5 Likes

Thanks @rapropos ! Worked like a charm!
I would love to have all this wrapped in the controller “delay” property as we used to