UNPKG

di-controls

Version:
74 lines (73 loc) 2.72 kB
import { ChangeDetectorRef, ModelSignal, Signal } from '@angular/core'; import { ControlValueAccessor, NgControl } from '@angular/forms'; import * as i0 from "@angular/core"; export interface DIControlValueAccessorConfig<T> { /** * Function that will be called when the current control receives an update from the host control or from the * Forms API. * * @param value - new value. */ onIncomingUpdate?: (value: T | null) => void; /** * Add support for native element. Which means that the control will * update the native element attributes like `disabled`. */ withNativeElementSupport?: boolean; } /** * Base implementation of ControlValueAccessor */ export declare abstract class DIControlValueAccessor<T> implements ControlValueAccessor { #private; protected readonly config?: DIControlValueAccessorConfig<T> | undefined; protected readonly model: Signal<T | null>; protected readonly ngControl: NgControl | null; protected readonly changeDetectorRef: ChangeDetectorRef; readonly disabled: ModelSignal<boolean>; protected touch: () => void; protected change: (value: T | null) => void; protected constructor(config?: DIControlValueAccessorConfig<T> | undefined); /** * Returns true if the control is not empty. */ get hasValue(): boolean; /** * Method is called by the forms API. * * @param fn - callback function to register on value change * @internal */ registerOnChange(fn: (value: T | null) => void): void; /** * Method is called by the forms API. * * @param fn - callback function to register on touch * @internal */ registerOnTouched(fn: () => void): void; /** * Method is called by the forms API to write to the view when programmatic changes from model to view are requested. * * @param obj - new value * @internal */ writeValue(obj: T | null): void; /** * Updates the model. * * @param value - new value */ internalUpdateModel(value: T | null): void; /** * Method is called by the forms API to write to the view when programmatic changes from model to view are requested. * * @param isDisabled - new value * @internal */ setDisabledState(isDisabled: boolean): void; private update; private addDisabledAttribute; static ɵfac: i0.ɵɵFactoryDeclaration<DIControlValueAccessor<any>, never>; static ɵdir: i0.ɵɵDirectiveDeclaration<DIControlValueAccessor<any>, never, never, { "disabled": { "alias": "disabled"; "required": false; "isSignal": true; }; }, { "disabled": "disabledChange"; }, never, never, true, never>; }