I am handling errors with MatSnackBar and I have problems with the position in which the dialog is displayed and it is not hidden automatically.
service.ts
facebookLogin() {
const provider = new firebase.auth.FacebookAuthProvider();
return this.oAuthLogin(provider);
}
private oAuthLogin(provider) {
return this.afAuth.auth.signInWithPopup(provider)
.then((credential) => {
this.pushUserData(credential.user)
this.router.navigate(['/userProfile'])
})
.catch(error => {
this.handleError(error);
});
}
private handleError(error: Error) {
console.error(error);
this.snackBar.open(error.message, this.action, { duration: 1000 });
}
component.ts
facebookLogin() {
this.auth.facebookLogin()
}
When I test it from the same component, everything works normal:
openSnackBar() {
this.snackBar.open(this.message, this.action, {
duration: 500,
});
}
I solved it in the following way, adding ngZone:
import { Injectable, NgZone } from '@angular/core';
constructor( public snackBar: MatSnackBar, private zone: NgZone )
private handleError(error: Error) {
console.error(error);
this.zone.run(() => {
this.snackBar.open(error.message, 'CERRAR', {
duration: 5000,
});
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With