File

projects/wms-framework/src/lib/directives/basedirective.ts

Description

Base class for directives which includes common functionality

Index

Properties
Methods

Properties

Public model
Type : any

The associated model to the directive

Methods

Protected loadModel
loadModel(elementRef: ElementRef)

Loads the model to the base directive from the component if the model was not already loaded

Parameters :
Name Type Optional
elementRef ElementRef No
Returns : void
import { ElementRef } from '@angular/core';

/**
 * Base class for directives which includes common functionality
 *
 * @export
 * @abstract
 * @class BaseDirective
 */
export abstract class BaseDirective {
  /**
   * The associated model to the directive
   *
   * @type {*}
   * @memberof BaseDirective
   */
  public model: any;

  /**
   * Loads the model to the base directive from the component if the model was not already loaded
   *
   * @private
   * @param {ElementRef} elementRef
   * @memberof BaseDirective
   */
  protected loadModel(elementRef: ElementRef) {
    if (this.model) {
      return;
    }

    /* eslint no-underscore-dangle: ["error", { "allow": ["__component"] }]*/
    const component = elementRef.nativeElement.__component;
    if (component && component.model) {
      this.model = component.model;
    } else if (component && component.context) {
      this.model = component.context;
    }
  }
}

result-matching ""

    No results matching ""