File

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

Description

Angular Directive for the wmClickAction

Implements

OnInit OnChanges OnDestroy

Metadata

Selector [wmClickAction]

Index

Properties
Methods
Inputs

Constructor

constructor(elementRef: ElementRef)

Constructor.

Parameters :
Name Type Optional
elementRef ElementRef No

Inputs

model
Type : any

Model of the element using the directive

wmClickAction
Type : any

wmClickAction property

wmClickActionParameter
Type : any

Directive action parameter

Methods

ngOnChanges
ngOnChanges(changes: SimpleChanges)

Angular life-cycle hook

Parameters :
Name Type Optional Description
changes SimpleChanges No

Simple changes parameter

Returns : void
ngOnDestroy
ngOnDestroy()

Angular life cycle hook.

Returns : void
ngOnInit
ngOnInit()

Angular life cycle hook.

Returns : void
setDependencyValue
setDependencyValue()

Sets the value to the Dependency property

Returns : void

Properties

model
Type : any
Decorators :
@Input()

Model of the element using the directive

wmClickAction
Type : any
Decorators :
@Input()

wmClickAction property

wmClickActionParameter
Type : any
Decorators :
@Input()

Directive action parameter

import {
  Directive,
  ElementRef,
  Input,
  OnChanges,
  OnDestroy,
  OnInit,
  SimpleChanges,
} from '@angular/core';
import {
  BaseDirective,
  ButtonBaseModel,
  clickActionProperty,
  setDependencyPropertyValue,
} from '@mobilize/wms-framework';

/**
 * Angular Directive for the wmClickAction
 *
 * @export
 * @class ClickActionDirective
 */
@Directive({
  selector: '[wmClickAction]',
})
export class ClickActionDirective
  extends BaseDirective
  implements OnInit, OnChanges, OnDestroy
{
  /**
   * wmClickAction property
   *
   * @type {any}
   * @memberof ClickActionDirective
   */
  @Input()
  wmClickAction: any;

  /**
   * Model of the element using the directive
   *
   * @type {any}
   * @memberof ClickActionDirective
   */
  @Input()
  model: any;

  /**
   * Directive action parameter
   *
   * @type {any}
   * @memberof ClickActionDirective
   */
  @Input()
  wmClickActionParameter: any;

  /**
   * Constructor.
   *
   * @memberof ClickActionDirective
   */
  constructor(private elementRef: ElementRef) {
    super();
  }

  /**
   * Angular life-cycle hook
   *
   * @param changes Simple changes parameter
   */
  ngOnChanges(changes: SimpleChanges): void {
    /* istanbul ignore else */
    if (
      changes.wmClickActionParameter &&
      !changes.wmClickActionParameter.isFirstChange()
    ) {
      this.setDependencyValue();
    }
  }

  /**
   * Angular life cycle hook.
   *
   * @memberof ClickActionDirective
   */
  ngOnInit(): void {
    this.loadModel(this.elementRef);
    this.setDependencyValue();
  }

  /**
   * Angular life cycle hook.
   *
   * @memberof ClickActionDirective
   */
  ngOnDestroy(): void {
    this.model?.setValue(clickActionProperty, null);
  }

  /**
   * Sets the value to the Dependency property
   *
   * @memberof ClickActionDirective
   */
  setDependencyValue(): void {
    if (this.wmClickAction && this.model instanceof ButtonBaseModel) {
      setDependencyPropertyValue(
        clickActionProperty,
        this.wmClickAction,
        this.model
      );
    }
  }
}

result-matching ""

    No results matching ""