1 import { Directive, EventEmitter, HostListener, Input, OnInit } from '@angular/core';
2 import { NgControl } from '@angular/forms';
4 import { FormatterService } from '../services/formatter.service';
7 selector: '[cdMilliseconds]'
9 export class MillisecondsDirective implements OnInit {
11 ngDataReady: EventEmitter<any>;
13 constructor(private control: NgControl, private formatter: FormatterService) {}
15 setValue(value: string): void {
16 const ms = this.formatter.toMilliseconds(value);
17 this.control.control.setValue(`${ms} ms`);
21 this.setValue(this.control.value);
22 if (this.ngDataReady) {
23 this.ngDataReady.subscribe(() => this.setValue(this.control.value));
27 @HostListener('blur', ['$event.target.value'])
28 onUpdate(value: string) {