Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { ToastyService } from 'ng2-toasty';
- import { ToastOptions } from 'ng2-toasty/src/toasty.service';
- import { InjectorInstance } from '../app.module';
- enum ToastyToastType {
- WARNING = 'warning', DEFAULT = 'default', ERROR = 'error', INFO = 'info', SUCCESS = 'success', WAIT = 'wait',
- }
- export class Toasty {
- static toastyService: ToastyService = null;
- static defaultConfig: ToastOptions = {
- title : null,
- msg : null,
- showClose: true,
- theme : 'bootstrap',
- timeout : 5 * 1000,
- onAdd : () => {},
- onRemove : () => {},
- };
- static warning( message = '', title = null, timeout?: number ): number { return this.toast( ToastyToastType.WARNING, title, message, timeout ); }
- static default( message = '', title = null, timeout?: number ): number { return this.toast( ToastyToastType.DEFAULT, title, message, timeout ); }
- static error( message = '', title = null, timeout?: number ): number { return this.toast( ToastyToastType.ERROR, title, message, timeout ); }
- static info( message = '', title = null, timeout?: number ): number { return this.toast( ToastyToastType.INFO, title, message, timeout ); }
- static success( message = '', title = null, timeout?: number ): number { return this.toast( ToastyToastType.SUCCESS, title, message, timeout ); }
- static wait( message = '', title = null, timeout?: number ): number { return this.toast( ToastyToastType.WAIT, title, message, timeout ); }
- static toasty(): ToastyService {
- if ( this.toastyService == null ) {
- console.log("get")
- this.toastyService = InjectorInstance.get<ToastyService>( ToastyService );
- }
- return this.toastyService;
- }
- static toast( toastType: ToastyToastType, message = null, title = null, timeout?: number ) {
- let id = null;
- this.toasty()[ toastType ]( {
- ...this.defaultConfig,
- ...{
- msg : message,
- title : title,
- timeout: ( timeout || 5 ) * 1000,
- onAdd : ( toast ) => {
- id = toast.id;
- },
- },
- } );
- return id;
- }
- static clearAll(): void {
- this.toasty().clearAll();
- };
- static clear( id: number ): void {
- this.toasty().clear( id );
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement