projects/wms-framework/src/lib/directives/basepropertydirective.directive.ts
Properties |
|
Methods |
Inputs |
constructor(elementRef?: ElementRef)
|
||||||||
Creates an instance of BasePropertyDirective.
Parameters :
|
model | |
Type : FrameworkElement
|
|
ngAfterContentInit |
ngAfterContentInit()
|
Angular lifeCycle hook
Returns :
void
|
ngOnInit |
ngOnInit()
|
Angular lifeCycle hook
Returns :
void
|
setPropertyValue |
setPropertyValue()
|
Returns :
void
|
model |
Type : FrameworkElement
|
Decorators :
@Input()
|
Protected propertyDescriptor |
Type : DependencyProperty
|
Protected propertyName |
Type : string
|
Default value : ''
|
import { Directive, ElementRef, Input, OnInit } from '@angular/core';
import { createBindingFromBindingInfo } from '../basecomponentmodel/Bindings/BindingUtils';
import { DependencyProperty } from '../basecomponentmodel/DependencyProperty';
import { FrameworkElement } from '../basecomponentmodel/FrameworkElement';
import { BaseDirective } from './basedirective';
@Directive()
export class BasePropertyDirective extends BaseDirective implements OnInit {
@Input()
model: FrameworkElement;
protected propertyName = '';
protected propertyDescriptor: DependencyProperty;
/**
* Creates an instance of BasePropertyDirective.
*
* @param {ElementRef} elementRef - Element reference
* @memberof BasePropertyDirective
*/
constructor(private elementRef?: ElementRef) {
super();
}
/**
* Angular lifeCycle hook
*
* @memberof BasePropertyDirective
*/
ngOnInit() {
this.loadModel(this.elementRef);
if (this.model) {
this.setPropertyValue();
}
}
/**
* Angular lifeCycle hook
*
* @memberof BasePropertyDirective
*/
ngAfterContentInit() {
if (!this.model) {
this.loadModel(this.elementRef);
this.setPropertyValue();
}
}
setPropertyValue() {
const propertyValue = this[this.propertyName];
if (typeof propertyValue?.bindingPath === 'string') {
this.model.SetBinding(
this.propertyDescriptor,
createBindingFromBindingInfo(propertyValue, this.model)
);
} else if (typeof propertyValue?.resourceKey === 'string') {
this.model.setValue(
this.propertyDescriptor,
this.model.getResourceByKey(propertyValue.resourceKey)
);
} else {
this.model.setValue(this.propertyDescriptor, propertyValue);
}
}
}