import {Injectable, ViewContainerRef} from '@angular/core'; import {ToastComponent} from '../components/toast/toast.component'; export enum ToastType { INFO, WARNING, ERROR } @Injectable({ providedIn: 'root' }) export class ToastsService { private vcr?: ViewContainerRef sendToast(type: ToastType, message: string, action?: {label: string, onAction: () => void}) { let compRef = this.vcr?.createComponent(ToastComponent)! compRef.setInput("message", message) compRef.setInput("type", type) compRef.setInput("action", action) } setRootViewContainerRef(vcr: ViewContainerRef) { this.vcr = vcr } }