]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { Directive, EventEmitter, HostListener, Input, OnInit } from '@angular/core'; |
2 | import { NgControl } from '@angular/forms'; | |
3 | ||
4 | import { FormatterService } from '../services/formatter.service'; | |
5 | ||
6 | @Directive({ | |
7 | selector: '[cdMilliseconds]' | |
8 | }) | |
9 | export class MillisecondsDirective implements OnInit { | |
10 | @Input() | |
11 | ngDataReady: EventEmitter<any>; | |
12 | ||
13 | constructor(private control: NgControl, private formatter: FormatterService) {} | |
14 | ||
15 | setValue(value: string): void { | |
16 | const ms = this.formatter.toMilliseconds(value); | |
17 | this.control.control.setValue(`${ms} ms`); | |
18 | } | |
19 | ||
20 | ngOnInit(): void { | |
21 | this.setValue(this.control.value); | |
22 | if (this.ngDataReady) { | |
23 | this.ngDataReady.subscribe(() => this.setValue(this.control.value)); | |
24 | } | |
25 | } | |
26 | ||
27 | @HostListener('blur', ['$event.target.value']) | |
9f95a23c | 28 | onUpdate(value: string) { |
11fdf7f2 TL |
29 | this.setValue(value); |
30 | } | |
31 | } |