diff --git a/src/app/components/dynamicdialog/dialogservice.ts b/src/app/components/dynamicdialog/dialogservice.ts index a06ddc24aac..2f891919b69 100755 --- a/src/app/components/dynamicdialog/dialogservice.ts +++ b/src/app/components/dynamicdialog/dialogservice.ts @@ -12,7 +12,7 @@ import { ObjectUtils } from 'primeng/utils'; */ @Injectable() export class DialogService { - dialogComponentRefMap: Map> = new Map(); + dialogComponentRefMap: Map, ComponentRef> = new Map(); constructor(private appRef: ApplicationRef, private injector: Injector, @Inject(DOCUMENT) private document: Document) {} /** @@ -22,12 +22,12 @@ export class DialogService { * @returns {DynamicDialogRef} DynamicDialog instance. * @group Method */ - public open(componentType: Type, config: DynamicDialogConfig): DynamicDialogRef { + public open(componentType: Type, config: DynamicDialogConfig): DynamicDialogRef { if (!this.duplicationPermission(componentType, config)) { return null; } - const dialogRef = this.appendDialogComponentToBody(config); + const dialogRef = this.appendDialogComponentToBody(config, componentType); this.dialogComponentRefMap.get(dialogRef).instance.childComponentType = componentType; @@ -38,15 +38,15 @@ export class DialogService { * @param {ref} DynamicDialogRef - DynamicDialog instance. * @group Method */ - public getInstance(ref: DynamicDialogRef) { + public getInstance(ref: DynamicDialogRef) { return this.dialogComponentRefMap.get(ref).instance; } - private appendDialogComponentToBody(config: DynamicDialogConfig) { + private appendDialogComponentToBody(config: DynamicDialogConfig, componentType: Type): DynamicDialogRef { const map = new WeakMap(); map.set(DynamicDialogConfig, config); - const dialogRef = new DynamicDialogRef(); + const dialogRef = new DynamicDialogRef(); map.set(DynamicDialogRef, dialogRef); const sub = dialogRef.onClose.subscribe(() => { @@ -75,7 +75,7 @@ export class DialogService { return dialogRef; } - private removeDialogComponentFromBody(dialogRef: DynamicDialogRef) { + private removeDialogComponentFromBody(dialogRef: DynamicDialogRef) { if (!dialogRef || !this.dialogComponentRefMap.has(dialogRef)) { return; } diff --git a/src/app/components/dynamicdialog/dynamicdialog-ref.ts b/src/app/components/dynamicdialog/dynamicdialog-ref.ts index 556641a6196..b560c071b26 100755 --- a/src/app/components/dynamicdialog/dynamicdialog-ref.ts +++ b/src/app/components/dynamicdialog/dynamicdialog-ref.ts @@ -1,9 +1,10 @@ import { Observable, Subject } from 'rxjs'; +import { Output, EventEmitter, Type } from '@angular/core'; /** * Dynamic Dialog instance. * @group Components */ -export class DynamicDialogRef { +export class DynamicDialogRef { constructor() {} /** * Closes dialog. @@ -117,4 +118,11 @@ export class DynamicDialogRef { * @group Events */ onMaximize: Observable = this._onMaximize.asObservable(); + + /** + * Event triggered on child component load. + * @param {*} value - Chi. + * @group Events + */ + readonly onChildComponentLoaded = new Subject(); } diff --git a/src/app/components/dynamicdialog/dynamicdialog.ts b/src/app/components/dynamicdialog/dynamicdialog.ts index 638b447da46..baa783271c1 100755 --- a/src/app/components/dynamicdialog/dynamicdialog.ts +++ b/src/app/components/dynamicdialog/dynamicdialog.ts @@ -309,6 +309,7 @@ export class DynamicDialogComponent implements AfterViewInit, OnDestroy { viewContainerRef?.clear(); this.componentRef = viewContainerRef?.createComponent(componentType); + this.dialogRef.onChildComponentLoaded.next(this.componentRef!.instance); } moveOnTop() {