File

src/app/shared/directives/iops.directive.ts

Implements

OnInit

Metadata

Selector [cdIops]

Index

Methods
Inputs
HostListeners

Constructor

constructor(formatter: FormatterService, ngControl: NgControl)
Parameters :
Name Type Optional
formatter FormatterService No
ngControl NgControl No

Inputs

ngDataReady
Type : EventEmitter<any>

HostListeners

blur
Arguments : '$event.target.value'
blur(value)

Methods

ngOnInit
ngOnInit()
Returns : void
setValue
setValue(value: string)
Parameters :
Name Type Optional
value string No
Returns : void
import { Directive, EventEmitter, HostListener, Input, OnInit } from '@angular/core';
import { NgControl } from '@angular/forms';

import { FormatterService } from '../services/formatter.service';

@Directive({
  selector: '[cdIops]'
})
export class IopsDirective implements OnInit {
  @Input()
  ngDataReady: EventEmitter<any>;

  constructor(private formatter: FormatterService, private ngControl: NgControl) {}

  setValue(value: string): void {
    const iops = this.formatter.toIops(value);
    this.ngControl.control.setValue(`${iops} IOPS`);
  }

  ngOnInit(): void {
    this.setValue(this.ngControl.value);
    if (this.ngDataReady) {
      this.ngDataReady.subscribe(() => this.setValue(this.ngControl.value));
    }
  }

  @HostListener('blur', ['$event.target.value'])
  onUpdate(value) {
    this.setValue(value);
  }
}

result-matching ""

    No results matching ""