src/lib/service/notifications/notifications.service.ts
Wrapper for Toastr Service
Methods |
constructor(toastrService: ToastrService)
|
||||||
Parameters :
|
confirm |
confirm(title: string, msg?: string, onAdd?: any, onRemove?: any)
|
Show confirm colored massage (blue)
Returns :
void
|
error | ||||||||||||||||||||
error(title: string, msg?: string, onActivateTick: )
|
||||||||||||||||||||
Show error colored massage (red)
Parameters :
Returns :
void
|
info |
info(title: string, msg?: string)
|
Show info colored massage (blue)
Returns :
void
|
success |
success(title: string, msg?: string)
|
Show success colored massage (green)
Returns :
void
|
wait |
wait(title: string, msg?: string)
|
can not be in use
Returns :
void
|
warning |
warning(title: string, msg?: string)
|
Show warning colored massage (yellow)
Returns :
void
|
import {Injectable} from '@angular/core';
import { ToastrService } from 'ngx-toastr';
/**
* Wrapper for Toastr Service
*/
@Injectable({
providedIn: 'root'
})
export class NotificationsService {
/**
* Default Notofication Options
*
*/
private options: any = {
closeButton: true,
positionClass: 'toast-bottom-right',
timeOut: 15000
};
constructor(private toastrService: ToastrService) {
}
/**
* Show info colored massage (blue)
*
* @param string title
* @param string msg
*/
info(title: string, msg?: string) {
this.toast(title, msg);
}
/**
* Show confirm colored massage (blue)
*
* @param string title
* @param string msg
* @param onAdd
* @param onRemove
*/
confirm(title: string, msg?: string, onAdd?: any, onRemove?: any) {
this.toast(title, msg, 'confirm', {onAdd, onRemove, timeOut: 7000});
}
/**
* Show success colored massage (green)
* @param string title
* @param string msg
*/
success(title: string, msg?: string) {
this.toast(title, msg, 'success');
}
/**
* can not be in use
*
* @param string title
* @param string msg
*/
wait(title: string, msg?: string) {
this.toast(title, msg, 'wait');
}
/**
* Show error colored massage (red)
*
* @param title title
* @param msg msg
* @param onActivateTick onActivateTick
*/
error(title: string, msg?: string, onActivateTick = false) {
this.toast(title, msg, 'error', {
closeButton: true,
timeOut: 7000,
onActivateTick
});
}
/**
* Show warning colored massage (yellow)
*
* @param string title
* @param string msg
*/
warning(title: string, msg?: string) {
this.toast(title, msg, 'warning');
}
/**
* Public wrapper for accessing the Toastr
*
* @param string title
* @param string msg
* @param string mode
* @param _options
*/
private toast(title: string, msg: string, mode?: string, _options?: {}) {
let options: any = Object.assign({}, this.options, _options);
// options.title = title || '';
// options.msg = msg || '';
this.doToast(msg, title, options, mode);
}
/**
* Accessing the toastr service
*
* @param string msg
* @param string title
* @param options
* @param string mode
*/
private doToast(msg: string, title: string, options: any, mode?: string) {
switch (mode) {
case 'success': {
this.toastrService.success(msg, title, options);
break;
}
// case 'wait': {
// this.toastrService.wait(msg, title, options);
// break;
// }
case 'error': {
this.toastrService.error(msg, title, options);
break;
}
case 'warning': {
this.toastrService.warning(msg, title, options);
break;
}
case 'confirm': {
this.toastrService.info(msg, title, options);
break;
}
default: {
this.toastrService.info(msg, title, options);
}
}
}
}