File

projects/i-components/src/lib/directives/setComplexPropertyValue.directive.ts

Description

Directive for setting complex properties in HTML

Implements

OnInit

Metadata

Selector [wmSetComplexPropertyValue]

Index

Properties
Methods
Inputs

Constructor

constructor(elementRef: ElementRef)

Creates an instance of SetComplexPropertyValue.

Parameters :
Name Type Optional
elementRef ElementRef<HTMLElement> No

Inputs

model
Type : any

Model

wmSetComplexPropertyValue
Type : Array<>

Directive info

Expected format : 'property name' vs component vs initialization method name vs component

Methods

ngOnInit
ngOnInit()

Initialization of this directive

Returns : void

Properties

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

result-matching ""

    No results matching ""