0

I am building an app in Angular/Ionic and would like to use the ion-loading component to show a loading icon while the page is still loading.

However, I can't find a lot of information about this in the documentation, but how do you actually check if all content has been loaded? It seems you have to assign a duration to the ion-loading component. Could someone point me in the right direction?

As a kind of workaround (code below) I forced the app to load everything sequentially but this is not ideal, because I'd still like the app to perform some actions in parallel to increase the loading speed.

  loading: any;
  async presentLoading() {
    this.loading = await this.loadingController.create({
      message: 'Loading...'
    });
    await this.loading.present();
  }

  async initializeApp() {
    this.presentLoading();
    await this.getData();
    await this.getCurrentDate();
    await this.loading.dismiss();
  }

  ngOnInit() {
    this.initializeApp();
  }
3
  • How are you loading your data/ page ? Commented Apr 17, 2020 at 12:19
  • Hi @NajamUsSaqib, not sure if I understand your question correctly. What I am doing is loading some data, applying some transformations and then showing it on the front-end. Commented Apr 17, 2020 at 12:56
  • how are you loading your data? are you using any HTTP api? if yes share your code. Commented Apr 17, 2020 at 14:29

1 Answer 1

1

If the main issue you're trying to solve is that you don't want to call getData() & getCurrentDate() sequentially then you may want to do something like this instead.

async initializeApp() {
    this.presentLoading();
    await Promise.all([
        this.getData();
        this.getCurrentDate();
    ])
    await this.loading.dismiss();
  }

This answer does a good job of explaining how Promise.all() works.

Also, you don't really need to await this.loading.present() & this.loading.dismiss() in this scenario.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.