| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import { Injectable } from '@angular/core';
- import { v4 as uuid } from 'uuid';
- interface ToastOptions {
- id: string;
- header: string;
- message: string;
- alertClass: 'danger' | 'warning' | 'info';
- delay?: number;
- }
- @Injectable({
- providedIn: 'root'
- })
- export class ToastService {
- public toasts: ToastOptions[] = [];
- constructor() {}
- public error(message: string, header: string, delay?: number) {
- this.toasts.push({
- id: uuid(),
- message,
- header,
- alertClass: 'danger',
- delay
- });
- }
- public warning(message: string, header: string, delay?: number) {
- this.toasts.push({
- id: uuid(),
- message,
- header,
- alertClass: 'warning',
- delay
- });
- }
- public info(message: string, header: string, delay?: number) {
- this.toasts.push({
- id: uuid(),
- message,
- header,
- alertClass: 'info',
- delay
- });
- }
- public remove(id: string) {
- const idx = this.toasts.findIndex(t => t.id === id);
- if (idx >= 0) this.toasts.splice(idx, 1);
- }
- }
|