import { Injectable } from '@angular/core'; import { Subject } from 'rxjs'; @Injectable({ providedIn: 'root', }) export class DetailsService { private detailsPanelSubject = new Subject(); detailsPanel$ = this.detailsPanelSubject.asObservable(); private closePanelSubject = new Subject(); closePanel$ = this.closePanelSubject.asObservable(); private resultSubject = new Subject(); result$ = this.resultSubject.asObservable(); public openPanel(component: any, data: any) { this.detailsPanelSubject.next({ component, data }); } // Is called from the dynamic component to close the offcanvas public closePanel(result: any, data?: any) { // console.log('closePanel', result); // Is listened to in the host component where the panel was opened, to initiate further steps this.resultSubject.next({ state: result, data: data }); this.closePanelSubject.next('close'); } }