Created
January 2, 2020 09:42
-
-
Save lydemann/d6048440e7d7f06e1ae6c286e5cf9931 to your computer and use it in GitHub Desktop.
data-picker.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-data-picker', | |
templateUrl: './data-picker.component.html', | |
styleUrls: ['./data-picker.component.scss'], | |
}) | |
export class DataPickerComponent implements ControlValueAccessor { | |
@Input() | |
public date: Date; | |
@Input() public minDate: Date; | |
@Input() public maxDate: Date; | |
@Input() public showError: Date; | |
@Input() public errorMessage: string = 'Invalid input'; | |
@Input() public placeholder: string = 'Choose a date'; | |
public dateChange: EventEmitter<Date> = new EventEmitter(); | |
public isDisabled = false; | |
private onTouched = Function; | |
// tslint:disable-next-line: member-ordering | |
public hasError: boolean = this.ngControl.invalid; | |
constructor(private ngControl: NgControl) { | |
ngControl.valueAccessor = this; | |
} | |
public onDateChange(dateInput: MatDatepickerInputEvent<Date>) { | |
const date = dateInput.target.value; | |
this.onChange(date); | |
this.onTouched(); | |
this.dateChange.next(date); | |
} | |
public writeValue(obj: Date): void { | |
this.date = obj; | |
} | |
public registerOnChange(fn: any): void { | |
this.onChange = fn; | |
} | |
public registerOnTouched(fn: any): void { | |
this.onTouched = fn; | |
} | |
public setDisabledState?(isDisabled: boolean): void { | |
this.isDisabled = isDisabled; | |
} | |
// tslint:disable-next-line: no-empty | |
private onChange = (val: any) => {}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment