Cleaned up repository and removed errors
This commit is contained in:
34
src/app/custom-input.component.ts
Normal file
34
src/app/custom-input.component.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import {ControlValueAccessor, FormControl, ValidationErrors, Validator} from '@angular/forms';
|
||||
|
||||
export abstract class CustomInputComponent implements ControlValueAccessor, Validator {
|
||||
protected value: number;
|
||||
protected parseError: boolean;
|
||||
private propagateChange: (_: any) => void = () => {};
|
||||
private propagateTouch: () => void = () => {};
|
||||
|
||||
// set initial value
|
||||
public abstract writeValue(obj: any): void;
|
||||
|
||||
// register function to notify on change
|
||||
public registerOnChange(fn: (_: any) => void): void {
|
||||
this.propagateChange = fn;
|
||||
}
|
||||
|
||||
// register function to notify on touch
|
||||
public registerOnTouched(fn: () => void): void {
|
||||
this.propagateTouch = fn;
|
||||
}
|
||||
|
||||
// validates the form, returns null when valid else the validation object
|
||||
public abstract validate(c: FormControl): ValidationErrors;
|
||||
|
||||
// on change
|
||||
protected onChange(value: any): void {
|
||||
this.propagateChange(this.value);
|
||||
}
|
||||
|
||||
// on touch
|
||||
protected onBlur(): void {
|
||||
this.propagateTouch();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user