How to dismiss the ion-loading?

#1

From the official Ionic docs:
[https://ionicframework.com/docs/api/loading](See it here)

async function presentLoading() {
  const loadingController = document.querySelector('ion-loading-controller');
  await loadingController.componentOnReady();

  const loading = await loadingController.create({
    message: 'Hellooo',
    duration: 2000
  });

  await loading.present();
}

That’s great. How to dismiss it programatically?

#2

Hi @raz-ride4you :wave:

You can dismiss a loading with loading.dismiss(): https://ionicframework.com/docs/api/loading#methods

Best,
Rodrigo

#3

Yes but how to actually implement this?
I have tried couple of things, nothing worked…

#4

Hi, @raz-ride4you
You can do like this:

async function presentLoading() {
  const loadingController = document.querySelector('ion-loading-controller');
  await loadingController.componentOnReady();

  const loading = await loadingController.create({
    message: 'Hellooo',
    duration: 2000
  });

  await loading.present();
  setTimeout(() => {
      console.log("timeout")
      loading.dismiss();
   }, 1000);
}

Here I’ve used timeout function it’ll dismiss loading after 1second.
Hope it will help you.
Thanks