details.service.ts 927 B

12345678910111213141516171819202122232425262728
  1. import { Injectable } from '@angular/core';
  2. import { Subject } from 'rxjs';
  3. @Injectable({
  4. providedIn: 'root',
  5. })
  6. export class DetailsService {
  7. private detailsPanelSubject = new Subject<any>();
  8. detailsPanel$ = this.detailsPanelSubject.asObservable();
  9. private closePanelSubject = new Subject<any>();
  10. closePanel$ = this.closePanelSubject.asObservable();
  11. private resultSubject = new Subject<any>();
  12. result$ = this.resultSubject.asObservable();
  13. public openPanel(component: any, data: any) {
  14. this.detailsPanelSubject.next({ component, data });
  15. }
  16. // Is called from the dynamic component to close the offcanvas
  17. public closePanel(result: any, data?: any) {
  18. // console.log('closePanel', result);
  19. // Is listened to in the host component where the panel was opened, to initiate further steps
  20. this.resultSubject.next({ state: result, data: data });
  21. this.closePanelSubject.next('close');
  22. }
  23. }