import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { ToasterService, Toast } from 'angular2-toaster'; import { TranslateService } from '@ngx-translate/core'; import {Observable} from 'rxjs/Observable'; @Injectable() export class SharedService { // Observable lang Source private _languageSource = new BehaviorSubject('en'); private _breadcrumbSource = new BehaviorSubject('home'); breadCrumb$ = this._breadcrumbSource.asObservable(); // Observable lang stream language$ = this._languageSource.asObservable(); constructor(private toasterService: ToasterService, private translate: TranslateService) { } // service command changeLanguage(lang) { this._languageSource.next(lang); } // service command changeBreadCrumb(breadcrumb) { this._breadcrumbSource.next(breadcrumb); } public popFailure = (body: string) => { this.popToast('error', 'toaster-title-failure', body); } public popSuccess = (body: string) => { this.popToast('success', 'toaster-title-success', body); } // control the loading screen private _loaderSource = new BehaviorSubject(false); public $loader = this._loaderSource.asObservable(); public showLoader(show: boolean) { this._loaderSource.next(show); } private _pdfDataReady = new BehaviorSubject(null); public $pdfDataReady = this._pdfDataReady.asObservable(); public pdfDataRready(pdfData) { this._pdfDataReady.next(pdfData); } public popToast = (toastType: string, title: string, body: string) => { this.toasterService.pop({ type: toastType, title: this.translate.instant(title), body: this.translate.instant(body) }); } }