projects/web-mev/src/app/core/notifications/notification.service.ts
Notification service
Methods |
constructor(snackBar: MatSnackBar, zone: NgZone)
|
|||||||||
|
Parameters :
|
| default | ||||||
default(message: string)
|
||||||
|
Parameters :
Returns :
void
|
| error | ||||||
error(message: string)
|
||||||
|
Parameters :
Returns :
void
|
| info | ||||||
info(message: string)
|
||||||
|
Parameters :
Returns :
void
|
| Private show | |||||||||
show(message: string, configuration: MatSnackBarConfig)
|
|||||||||
|
Parameters :
Returns :
void
|
| success | ||||||
success(message: string)
|
||||||
|
Parameters :
Returns :
void
|
| warn | ||||||
warn(message: string)
|
||||||
|
Parameters :
Returns :
void
|
import { Injectable, NgZone } from '@angular/core';
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
/**
* Notification service
*
*/
@Injectable({
providedIn: 'root'
})
export class NotificationService {
constructor(
private readonly snackBar: MatSnackBar,
private readonly zone: NgZone
) {}
default(message: string) {
this.show(message, {
duration: 2000,
panelClass: 'default-notification-overlay'
});
}
info(message: string) {
this.show(message, {
duration: 2000,
panelClass: 'info-notification-overlay'
});
}
success(message: string) {
this.show(message, {
duration: 2000,
panelClass: 'success-notification-overlay'
});
}
warn(message: string) {
this.show(message, {
duration: 2500,
panelClass: 'warning-notification-overlay'
});
}
error(message: string) {
this.show(message, {
duration: 10000,
panelClass: 'error-notification-overlay'
});
}
private show(message: string, configuration: MatSnackBarConfig) {
// Need to open snackBar from Angular zone to prevent issues with its position per
// https://stackoverflow.com/questions/50101912/snackbar-position-wrong-when-use-errorhandler-in-angular-5-and-material
this.zone.run(() => this.snackBar.open(message, null, configuration));
}
}