### File

`projects/commons/src/lib/elements/dialog/services/dialog.service.ts`

### Index

###### Methods
Private getComponentRef Public open

### Constructor

`constructor(injector: Injector, domService: DomService)`
Defined in projects/commons/src/lib/elements/dialog/services/dialog.service.ts:10
Parameters :
Name | Type | Optional
injector | `Injector` | No
domService | `DomService` | No

### Methods

Private getComponentRef
`getComponentRef(config: any)`
Defined in projects/commons/src/lib/elements/dialog/services/dialog.service.ts:26
Parameters :
Name | Type | Optional
config | `any` | No
Returns : `any`

Public open
`open(componentOrTemplateRef: ComponentType | any | TemplateRef, config: any)`
Defined in projects/commons/src/lib/elements/dialog/services/dialog.service.ts:16
Type parameters : T
Parameters :
Name | Type | Optional
componentOrTemplateRef | `ComponentType<T> | any | TemplateRef<T>` | No
config | `any` | No
Returns : `any`

    import { ComponentType } from '@angular/core/src/render3';
    import { Injectable, Injector, TemplateRef } from '@angular/core';

    import { DialogComponent } from '../components';
    import { DomService } from '../../../shared/dom/dom.service';
    import { extendObject } from '../../../shared/util/object-extend';
    import { PortalInjector } from '../../../shared/portal/portal-injector';

    @Injectable()
    export class DialogService {
        constructor(
            private injector: Injector,
            private domService: DomService,
        ) {}

        public open<T>(componentOrTemplateRef: ComponentType<T> | any | TemplateRef<T>, config: any): any {
            config = { ...{ hasBackdrop: true }, ...config };

            const componentRef = this.getComponentRef(config);

            (componentRef.instance as any)._setComponent(componentOrTemplateRef);

            return componentRef.instance as DialogComponent<T>;
        }

        private getComponentRef(config: any) {
            const injectionTokens = new WeakMap();

            injectionTokens.set(DialogComponent, DialogComponent);

            const injector = new PortalInjector(this.injector, injectionTokens);

            const componentRef = this.domService.attachComponentPortal(DialogComponent, injector);

            (componentRef.instance as any).config = extendObject({}, config);

            (componentRef.instance as any).afterClosed().subscribe(() => {
                componentRef.destroy();
            });

            return componentRef;
        }
    }

# result-matching ""

# No results matching ""