File

projects/wms-framework/src/lib/models/services/dialog/dialog.service.ts

Index

Properties
Methods

Constructor

constructor(cfr: ComponentFactoryResolver)

Constructor

Parameters :
Name Type Optional
cfr ComponentFactoryResolver No

Methods

init
init(el: ViewContainerRef)

Initialize viewContainer reference, this must be called from Aplication

Parameters :
Name Type Optional
el ViewContainerRef No
Returns : void
initializeDialog
initializeDialog(content: any, componentFactory: any, dialogRef: any, options: any)

Appends dialog to the current container

Parameters :
Name Type Optional
content any No
componentFactory any No
dialogRef any No
options any No
Returns : any

{*}

open
open(object: any)

Open function that resolves dialog content component

Parameters :
Name Type Optional
object any No
Returns : any

{*}

remove
remove(reference: any)
Parameters :
Name Type Optional
reference any No
Returns : void

Properties

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);
  }
}

result-matching ""

    No results matching ""