# All files / src/app/shared/directives milliseconds.directive.ts

65% Statements 13/20
70% Branches 7/10
20% Functions 1/5
66.67% Lines 10/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    3292x
    92x

    92x

    92x

    92x

    1x

    92x

    92x

    184x

    92x
     import { Directive, EventEmitter, HostListener, Input, OnInit } from '@angular/core';
    import { NgControl } from '@angular/forms';

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

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

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

      setValue(value: string): void {
        const ms = this.formatter.toMilliseconds(value);
        this.control.control.setValue(`${ms} ms`);
      }

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

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