projects/k-components/src/lib/components/button/button.component.ts
Angular Component for the Button Control
| changeDetection | ChangeDetectionStrategy.OnPush | 
| selector | wm-button | 
| templateUrl | ./button.component.html | 
| Properties | 
| Methods | 
| Inputs | 
| Public constructor(injector: Injector, injectedModel: ButtonModel) | |||||||||
| Creates an instance of ButtonComponent. 
                                    Parameters :
                                     
 | 
| click | |
| Type : EventEmitter<any> | |
| Default value : new EventEmitter() | |
| Event Emmiter. EventEmitter normally called in the ClickHandler. | |
| model | |
| Type : ButtonModel | |
| Object with properties and events for the Button. | |
| clickHandler | 
| clickHandler() | 
| Event handler for when the user click the button. Emit the click EventEmitter output. 
                        Returns :          void | 
| isDisabled | 
| isDisabled() | 
| Disable the Button element if the model.IsEnabled is false. 
                        Returns :          boolean{boolean} | 
| ngOnInit | 
| ngOnInit() | 
| Angular lifeCycle hook Assign the model property with a ButtonModel instance. 
                        Returns :          void | 
| triggerClick | 
| triggerClick() | 
| Event handler from the HTML Element Button for when the user click the button. Calls the Component clickHandler method 
                        Returns :          void | 
| click | 
| Type : EventEmitter<any> | 
| Default value : new EventEmitter() | 
| Decorators : 
                            @Input() | 
| Event Emmiter. EventEmitter normally called in the ClickHandler. | 
| Public model | 
| Type : ButtonModel | 
| Decorators : 
                            @Input() | 
| Object with properties and events for the Button. | 
import {
  Component,
  Input,
  EventEmitter,
  Injector,
  Optional,
} from '@angular/core';
import {
  AngularComponentId,
  ButtonModel,
  ComponentId,
} from '@mobilize/wms-framework';
/**
 * Angular Component for the Button Control
 *
 * @export
 * @class ButtonComponent
 */
@Component({
  selector: 'wm-button',
  templateUrl: './button.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
@ComponentId([AngularComponentId.button])
export class ButtonComponent {
  /**
   * Object with properties and events for the Button.
   *
   * @type {ButtonModel}
   * @memberof ButtonComponent
   */
  @Input()
  public model: ButtonModel;
  /**
   * Event Emmiter.
   * EventEmitter normally called in the ClickHandler.
   *
   * @type {EventEmitter<any>}
   * @memberof ButtonComponent
   */
  @Input()
  click: EventEmitter<any> = new EventEmitter();
  /**
   * Creates an instance of ButtonComponent.
   * @param {Injector} injector
   * @param {ButtonModel} [injectedModel=null]
   * @memberof ButtonComponent
   */
  public constructor(
    private injector: Injector,
    @Optional() protected injectedModel: ButtonModel = null
  ) {
    this.model = injectedModel;
  }
  /**
   * Event handler from the HTML Element Button for when the user click the button.
   * Calls the Component clickHandler method
   * @memberof ButtonComponent
   */
  triggerClick(): void {
    this.clickHandler();
  }
  /**
   * Event handler for when the user click the button.
   * Emit the click EventEmitter output.
   *
   * @memberof ButtonComponent
   */
  clickHandler(): void {
    this.model?.OnClick();
    this.click.emit(this);
  }
  /**
   * Disable the Button element if the model.IsEnabled is false.
   *
   * @return {*}  {boolean}
   * @memberof ButtonComponent
   */
  isDisabled(): boolean {
    return this.model?.IsEnabled === false;
  }
  /**
   * Angular lifeCycle hook
   * Assign the model property with a ButtonModel instance.
   * @memberof ButtonComponent
   */
  ngOnInit(): void {
    this.model = this.model || this.injectedModel || new ButtonModel();
  }
}
<button
  (click)="clickHandler()"
  [disabled]="model?.IsEnabled"
  class="btn btn-primary"
>
  <ng-content></ng-content>
</button>