projects/i-components/src/lib/directives/setComplexPropertyValue.directive.ts
Directive for setting complex properties in HTML
Selector | [wmSetComplexPropertyValue] |
Properties |
Methods |
Inputs |
constructor(elementRef: ElementRef
|
||||||
Creates an instance of SetComplexPropertyValue.
Parameters :
|
model | |
Type : any
|
|
Model |
wmSetComplexPropertyValue | |
Type : Array<>
|
|
Directive info Expected format : 'property name' vs component vs initialization method name vs component |
ngOnInit |
ngOnInit()
|
Initialization of this directive
Returns :
void
|
model |
Type : any
|
Decorators :
@Input()
|
Model |
wmSetComplexPropertyValue |
Type : Array<>
|
Decorators :
@Input()
|
Directive info Expected format : 'property name' vs component vs initialization method name vs component |
import { Directive, Input, ElementRef, OnInit } from '@angular/core';
import { FrameworkElement, BaseDirective } from '@mobilize/wms-framework';
/**
* Directive for setting complex properties in HTML
*
* @export
* @class SetComplexPropertyValue
* @extends {BaseDirective}
*/
@Directive({
selector: '[wmSetComplexPropertyValue]',
})
export class SetComplexPropertyValueDirective
extends BaseDirective
implements OnInit
{
/**
* Model
*
* @type {*}
* @memberof SetComplexPropertyValue
*/
@Input()
model: any;
/**
* Directive info
*
* Expected format : 'property name' vs component vs initialization method name vs component
*
* @type {Array<[string, any, string, any]>}
* @memberof SetComplexPropertyValue
*/
@Input()
wmSetComplexPropertyValue: Array<[string, any, string, any]>;
/**
* Creates an instance of SetComplexPropertyValue.
* @param {ElementRef<HTMLElement>} elementRef
* @memberof SetComplexPropertyValue
*/
/* istanbul ignore next */
constructor(private elementRef: ElementRef<HTMLElement>) {
super();
}
/**
* Initialization of this directive
*
* @memberof SetComplexPropertyValue
*/
ngOnInit(): void {
this.loadModel(this.elementRef);
if (this.model instanceof FrameworkElement) {
for (const tuple of this.wmSetComplexPropertyValue) {
const value = tuple[1][tuple[2]](tuple[3]);
/* istanbul ignore next */
if (typeof tuple[1][tuple[0]] === 'function') {
this.model.setValue(tuple[1][tuple[0]](), value);
} else {
this.model[tuple[0]] = value;
}
}
}
}
}