import { Injectable } from '@angular/core' ; import { environment } from '@environments/environment' ; import { ToastrService } from 'ngx-toastr' ; import { DesktopNotificationService } from './desktop-notification.service' ; import { MobileNotificationService } from './mobile-notification.service' ; import { WebNotificationService } from './web-notification.service' ; export function notificationFactory ( toastrService ) { if ( environment . desktop ) { return new DesktopNotificationService ( ) ; } if ( environment . mobile ) { return new MobileNotificationService ( ) ; } return new WebNotificationService ( toastrService ) ; } export interface INotificationService { showError ( title , message , icon ? ) ; showInfo ( title , message , icon ? ) ; showSuccess ( title , message , icon ? ) ; showWarning ( title , message , icon ? ) ; } @ Injectable ( { providedIn : 'root' , useFactory : notificationFactory , deps : [ ToastrService ] } ) export abstract class AbstractNotificationService implements INotificationService { abstract showError ( title , message , icon ? ) ; abstract showInfo ( title , message , icon ? ) ; abstract showSuccess ( title , message , icon ? ) ; abstract showWarning ( title , message , icon ? ) ; }