projects/wms-framework/src/lib/directives/basedirective.ts
Base class for directives which includes common functionality
Properties |
|
Methods |
|
Public model |
Type : any
|
The associated model to the directive |
Protected loadModel | ||||||
loadModel(elementRef: ElementRef)
|
||||||
Loads the model to the base directive from the component if the model was not already loaded
Parameters :
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;
}
}
}