projects/wms-framework/src/lib/models/services/dialog/dialog.service.ts
Properties |
Methods |
constructor(cfr: ComponentFactoryResolver)
|
||||||
Constructor
Parameters :
|
init | ||||||
init(el: ViewContainerRef)
|
||||||
Initialize viewContainer reference, this must be called from Aplication
Parameters :
Returns :
void
|
initializeDialog | |||||||||||||||
initializeDialog(content: any, componentFactory: any, dialogRef: any, options: any)
|
|||||||||||||||
Appends dialog to the current container
Parameters :
Returns :
any
{*} |
open | ||||||
open(object: any)
|
||||||
Open function that resolves dialog content component
Parameters :
Returns :
any
{*} |
remove | ||||||
remove(reference: any)
|
||||||
Parameters :
Returns :
void
|
viewcontainerReference |
Type : any
|
View ContainerReference |
import {
ComponentFactoryResolver,
ComponentRef,
Injectable,
ViewContainerRef,
} from '@angular/core';
@Injectable()
export class DialogService {
/**
* View ContainerReference
*
* @type {*}
* @memberof DialogService
*/
viewcontainerReference: any;
/**
* Constructor
* @param {ComponentFactoryResolver} cfr
* @memberof DialogService
*/
constructor(private cfr: ComponentFactoryResolver) {}
/**
* Initialize viewContainer reference, this must be called from Aplication
*
* @param {ViewContainerRef} el
* @memberof DialogService
*/
init(el: ViewContainerRef) {
this.viewcontainerReference = el;
}
/**
* Open function that resolves dialog content component
*
* @param {*} object
* @return {*} {*}
* @memberof DialogService
*/
open(object: any): any {
const componentFactory = this.cfr.resolveComponentFactory(object.content);
const dialogRef = {
close: () => {},
content: null,
dialog: null,
result: null,
};
return this.initializeDialog(
object.content,
componentFactory,
dialogRef,
object
);
}
/**
* Appends dialog to the current container
*
* @param {*} content
* @param {*} componentFactory
* @param {*} dialogRef
* @param {*} options
* @return {*} {*}
* @memberof DialogService
*/
initializeDialog(
content: any,
componentFactory: any,
dialogRef: any,
options: any
): any {
const componentFinal =
this.viewcontainerReference.createComponent(componentFactory);
let childComponent = componentFinal.instance;
childComponent.openFlag = true;
childComponent.parentRef = this.viewcontainerReference.get(
this.viewcontainerReference.length - 1
);
dialogRef.dialog = content || {};
dialogRef.content = componentFinal;
dialogRef.result = {};
return dialogRef;
}
remove(reference: any) {
if (this.viewcontainerReference.length < 1) return;
let vcrIndex: number = this.viewcontainerReference.indexOf(reference);
// removing component from container
this.viewcontainerReference.remove(vcrIndex);
}
}