source: trip-planner-front/node_modules/primeng/esm2020/dynamicdialog/dialogservice.mjs@ 1ad8e64

Last change on this file since 1ad8e64 was 59329aa, checked in by Ema <ema_spirova@…>, 3 years ago

adding photos

  • Property mode set to 100644
File size: 9.1 KB
RevLine 
[59329aa]1import { Injectable } from '@angular/core';
2import { DynamicDialogComponent } from './dynamicdialog';
3import { DynamicDialogInjector } from './dynamicdialog-injector';
4import { DynamicDialogConfig } from './dynamicdialog-config';
5import { DynamicDialogRef } from './dynamicdialog-ref';
6import * as i0 from "@angular/core";
7export class DialogService {
8 constructor(componentFactoryResolver, appRef, injector) {
9 this.componentFactoryResolver = componentFactoryResolver;
10 this.appRef = appRef;
11 this.injector = injector;
12 this.dialogComponentRefMap = new Map();
13 }
14 open(componentType, config) {
15 const dialogRef = this.appendDialogComponentToBody(config);
16 this.dialogComponentRefMap.get(dialogRef).instance.childComponentType = componentType;
17 return dialogRef;
18 }
19 appendDialogComponentToBody(config) {
20 const map = new WeakMap();
21 map.set(DynamicDialogConfig, config);
22 const dialogRef = new DynamicDialogRef();
23 map.set(DynamicDialogRef, dialogRef);
24 const sub = dialogRef.onClose.subscribe(() => {
25 this.dialogComponentRefMap.get(dialogRef).instance.close();
26 });
27 const destroySub = dialogRef.onDestroy.subscribe(() => {
28 this.removeDialogComponentFromBody(dialogRef);
29 destroySub.unsubscribe();
30 sub.unsubscribe();
31 });
32 const componentFactory = this.componentFactoryResolver.resolveComponentFactory(DynamicDialogComponent);
33 const componentRef = componentFactory.create(new DynamicDialogInjector(this.injector, map));
34 this.appRef.attachView(componentRef.hostView);
35 const domElem = componentRef.hostView.rootNodes[0];
36 document.body.appendChild(domElem);
37 this.dialogComponentRefMap.set(dialogRef, componentRef);
38 return dialogRef;
39 }
40 removeDialogComponentFromBody(dialogRef) {
41 if (!dialogRef || !this.dialogComponentRefMap.has(dialogRef)) {
42 return;
43 }
44 const dialogComponentRef = this.dialogComponentRefMap.get(dialogRef);
45 this.appRef.detachView(dialogComponentRef.hostView);
46 dialogComponentRef.destroy();
47 this.dialogComponentRefMap.delete(dialogRef);
48 }
49}
50DialogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: DialogService, deps: [{ token: i0.ComponentFactoryResolver }, { token: i0.ApplicationRef }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
51DialogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: DialogService });
52i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: DialogService, decorators: [{
53 type: Injectable
54 }], ctorParameters: function () { return [{ type: i0.ComponentFactoryResolver }, { type: i0.ApplicationRef }, { type: i0.Injector }]; } });
55//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGlhbG9nc2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9hcHAvY29tcG9uZW50cy9keW5hbWljZGlhbG9nL2RpYWxvZ3NlcnZpY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFVBQVUsRUFBMkYsTUFBTSxlQUFlLENBQUM7QUFDcEksT0FBTyxFQUFFLHNCQUFzQixFQUFFLE1BQU0saUJBQWlCLENBQUM7QUFDekQsT0FBTyxFQUFFLHFCQUFxQixFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDakUsT0FBTyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFDN0QsT0FBTyxFQUFFLGdCQUFnQixFQUFFLE1BQU0scUJBQXFCLENBQUM7O0FBR3ZELE1BQU0sT0FBTyxhQUFhO0lBSXRCLFlBQW9CLHdCQUFrRCxFQUFVLE1BQXNCLEVBQVUsUUFBa0I7UUFBOUcsNkJBQXdCLEdBQXhCLHdCQUF3QixDQUEwQjtRQUFVL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gZGlhbG9nQ29tcG9uZW50UmVmID0gdGhpcy5kaWFsb2dDb21wb25lbnRSZWZNYXAuZ2V0KGRpYWxvZ1JlZik7XG4gICAgICAgIHRoaXMuYXBwUmVmLmRldGFjaFZpZXcoZGlhbG9nQ29tcG9uZW50UmVmLmhvc3RWaWV3KTtcbiAgICAgICAgZGlhbG9nQ29tcG9uZW50UmVmLmRlc3Ryb3koKTtcbiAgICAgICAgdGhpcy5kaWFsb2dDb21wb25lbnRSZWZNYXAuZGVsZXRlKGRpYWxvZ1JlZik7XG4gICAgfVxufVxuIl19
Note: See TracBrowser for help on using the repository browser.