Ad
How To Show A PresentAlert Inside A Method Then On Ionic 4?
I'm trying to show a presentAlert inside a "then method", adding a document on a collection (Firebase + Ionic 4, if its successful, it should appear the alert). But the problem is I cannot reach the presentAlert method if i'm calling from inside the then method.
addObject() {
this.afs.collection("Objects").add(this.object)
.then(function () {
console.log("Object successfully written!");
this.presentAlert() //Doesn't work
})
.catch(function (error) {
console.error(error);
});
}
async presentAlert() {
const alert = await this.alertController.create({
header: 'Thank you!',
message: 'This Object has been uploaded succesfully :)',
buttons: ['OK']
});
await alert.present();
}
Ad
Answer
Change the following:
.then(function () {
console.log("Object successfully written!");
this.presentAlert() //Doesn't work
})
.catch(function (error) {
console.error(error);
});
}
into this:
.then(() => {
console.log("Object successfully written!");
this.presentAlert() //Doesn't work
})
.catch((error) => {
console.error(error);
});
}
Ad
source: stackoverflow.com
Related Questions
- → How can I query Firebase for an equalTo boolean parameter?
- → How can I access nested data in Firebase with React?
- → Firebase simple blog (confused with security rules)
- → Removing item in Firebase with React, re-render returns item undefined
- → AngularJS Unknown Provider Error (Firebase & AngularFire)
- → How do you pass top level component state down to Routes using react-router?
- → "this" is null in firebase query function in reactjs
- → Angular Module Failed to Load
- → Multiple dex files define Lcom/google/android/gms/internal/zzrx;
- → Joining Firebase tables in React
- → How can I make add firepad to my reactjs project?
- → How to use Cloud Functions for Firebase to prerender pages for SEO?
- → React.js component has null state?
Ad