CngxErrorState
projects/common/interactive/error-state/error-state.directive.ts
Import#
import { CngxErrorState } from '@cngx/common/interactive'
Description#
Marks any DOM element as carrying an error state.
Generic host-element marker - works on cngx, Material, CDK, native HTML,
and third-party hosts. Toggles the .cngx-error class hook plus reactive
aria-invalid / aria-errormessage attributes when the bound boolean is
true. The directive is purely presentational; it does not own the error
state itself, it only reflects it.
The cngxErrorState input takes a plain boolean. Consumers binding a
signal write [cngxErrorState]="form.email().invalid()" - the signal is
invoked at the binding site (canonical Angular pattern), not detected at
runtime.
<input
[cngxErrorState]="emailField().invalid()"
cngxErrorMessageId="email-error"
/>
<span id="email-error" role="alert">Please enter a valid email.</span>