Mahmoud Ismail
Mahmoud Ismail

Reputation: 1617

Ionic2: loading dismiss not working

Loading component in ionic 2 working fine, for present the loading i've used below code.

let loading = Loading.create({
    content: "Please wait..."
 });

this.nav.present(this.loading);

but my Question when i've using this.loading.dimiss(); it's not working any suggestions plz ?

Upvotes: 0

Views: 1399

Answers (2)

John Behan
John Behan

Reputation: 584

Are you calling this from a callback of an Asynchronous function?

If so you will have to do something like

let loading = Loading.create({
    content: "Please wait..."
 });

this.nav.present(this.loading);

let me = this;


asyncFunction.load(me)
.then(data => {
......... do something with data ........
// when ready close loading
me.loading.dismiss();
});

You need to pass a reference to this into the asynchronous function so you can keep a reference to it available to the callback

Upvotes: 1

Mahmoud Ismail
Mahmoud Ismail

Reputation: 1617

I solved it by puting the code after dismiss() in the .then() of the promise that the dismiss() function returns.

eg : this.loading.dismiss().then(() => { /* PUT YOUR CODE HERE */ })

Upvotes: 0

Related Questions