Ioni c 4 LoadingController - PullRequest
       3

Ioni c 4 LoadingController

0 голосов
/ 13 марта 2020

Я пытаюсь добавить LoadingController в мое приложение Ioni c 5.

С приведенным ниже кодом появляется счетчик загрузки:

async presentLoading() {
    const loading = await this.loadingCtrl.create({
      message: 'Please wait...',
    });
    await loading.present();
  }

getPosts() {

    this.posts = [];
    this.presentLoading();

    query.get()
      .then((docs) => {
        docs.forEach((doc) => {
          this.posts.push(doc);
        })
      }).catch((err) => {
        console.log(err)
      })

}

Но я не знаете, как отключить LoadingController после заполнения массива posts .

Может кто-нибудь показать мне, как это делается?

1 Ответ

1 голос
/ 13 марта 2020

Вы должны dismiss контроллер. Для этого вам нужно будет сохранить ссылку на него, что-то вроде этого:

async presentLoading() {
    this.loading = await this.loadingCtrl.create({
        message: 'Please wait...',
    });
    await this.loading.present();
}
getPosts() {
    this.posts = [];
    this.presentLoading();
    query.get()
    .then((docs) => {
        docs.forEach((doc) => {
            this.posts.push(doc);
            this.loading.dismiss();
        })
    }).catch((err) => {
        console.log(err)
    })
}

Если вам нужно получить уведомление, когда происходит увольнение, вы можете прослушать событие onDidDismiss.

Ссылки:

...