import { Injectable, Injector } from '@angular/core'; import { ControlContainer, ControlValueAccessor } from '@angular/forms'; @Injectable() export class PiFormControl implements ControlValueAccessor { value!: number | string | Array | boolean; onChange = (value: number | string | Array | boolean) => {}; onTouched = () => {}; disabled = false; focused = false; touched = false; constructor(protected injector: Injector) {} get controlContainer(): any { return this.injector.get(ControlContainer); } writeValue(value: number | string | Array | boolean) { this.value = value; } registerOnChange(onChange: any) { this.onChange = onChange; } registerOnTouched(onTouched: any) { this.onTouched = onTouched; } markAsTouched() { if (!this.touched) { this.onTouched(); this.touched = true; } } setDisabledState(disabled: boolean) { this.disabled = disabled; } onFocus(): void { this.focused = true; } onBlur(): void { this.focused = false; } }