import { Injectable } from "@angular/core" ; import { Observable } from "rxjs/Observable" ; import { Subject } from "rxjs/Subject" ; import { Toast , ToastEvent } from "./toast" ; @ Injectable ( ) export class ToastService { private toastEvents : Subject < ToastEvent > = new Subject < Toast > ( ) ; get events ( ) : Observable < ToastEvent > { return this . toastEvents ; } success ( message ) { this . publish ( { message : message , level : 'success' } ) ; } warning ( message ) { this . publish ( { message : message , level : 'warning' } ) ; } error ( message ) { this . publish ( { message : message , level : 'error' } ) ; } private publish ( toast ) { this . toastEvents . next ( toast ) ; } }