Skip to content

Instantly share code, notes, and snippets.

@melcor76
Last active March 7, 2022 18:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melcor76/e6e53f0442e54619b2992a30b0894f88 to your computer and use it in GitHub Desktop.
Save melcor76/e6e53f0442e54619b2992a30b0894f88 to your computer and use it in GitHub Desktop.
Error handling - notification.service.ts
import { Injectable} from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
@Injectable({
providedIn: 'root'
})
export class NotificationService {
constructor(public snackBar: MatSnackBar) { }
showSuccess(message: string): void {
this.snackBar.open(message);
}
showError(message: string): void {
// The second parameter is the text in the button.
// In the third, we send in the css class for the snack bar.
this.snackBar.open(message, 'X', {panelClass: ['error']});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment