-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinput-date.component.ts
More file actions
50 lines (43 loc) · 1.02 KB
/
input-date.component.ts
File metadata and controls
50 lines (43 loc) · 1.02 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import {Component, forwardRef} from '@angular/core';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
@Component({
selector: 'app-input-date',
templateUrl: './input-date.component.html',
styleUrls: ['./input-date.component.scss'],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => InputDateComponent),
multi: true
}
]
})
export class InputDateComponent implements ControlValueAccessor {
value: string;
isDisabled: boolean;
onChange = (_: any) => { };
onTouch = () => { };
constructor() {
}
onInput(value: string) {
this.value = value;
this.onTouch();
this.onChange(this.value);
}
writeValue(value: any): void {
if (value) {
this.value = value || '';
} else {
this.value = '';
}
}
registerOnChange(fn: any): void {
this.onChange = fn;
}
registerOnTouched(fn: any): void {
this.onTouch = fn;
}
setDisabledState(isDisabled: boolean): void {
this.isDisabled = isDisabled;
}
}