Skip to main content
cngx-src documentation

CngxErrorState

DirectivePrimaryv0.1.0WCAG AA

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>

https://cngxjs.github.io/cngx/examples/#/common/interactive/error/state/basic-boolean-flag-flips-aria-invalid-aria-errormessage https://cngxjs.github.io/cngx/examples/#/common/interactive/error/state/without-message-id-class-hook-aria-invalid-only

Metadata#

Host#

Index#

Inputs#

cngxErrorMessageId#string | null
input()

Optional id of the element rendering the error message text.

default null
cngxErrorState#boolean
input()Required

HostBindings#

BindingExpression
[class.cngx-error]cngxErrorState()
[attr.aria-invalid]ariaInvalid()
[attr.aria-errormessage]ariaErrorMessage()