Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MatSnackBar position error and hide

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.

enter image description here

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,
});
}
like image 302
Paco Zevallos Avatar asked Dec 13 '22 16:12

Paco Zevallos


1 Answers

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,
    });
  });
}
like image 61
Paco Zevallos Avatar answered Dec 16 '22 06:12

Paco Zevallos