Files
WinStudentGoalTracker/ui/winstudentgoaltracker/src/app/shared/services/toast.service.ts
T
Armin Abaye c7989110eb 3 ui updates
2026-04-13 17:41:27 -04:00

26 lines
645 B
TypeScript

import { Injectable, signal } from '@angular/core';
export type ToastType = 'success' | 'error' | 'info';
export interface Toast {
id: number;
message: string;
type: ToastType;
}
@Injectable({ providedIn: 'root' })
export class ToastService {
private nextId = 0;
readonly toasts = signal<Toast[]>([]);
show(message: string, type: ToastType = 'success') {
const id = ++this.nextId;
this.toasts.update(list => [...list, { id, message, type }]);
setTimeout(() => this.dismiss(id), 3000);
}
dismiss(id: number) {
this.toasts.update(list => list.filter(t => t.id !== id));
}
}