CngxErrorAggregator
projects/common/interactive/error-aggregator/error-aggregator.directive.ts
Import#
import { CngxErrorAggregator } from '@cngx/common/interactive'
Description#
Aggregates one-or-more CngxErrorSource children into a single live A11y surface.
Each registered source contributes a key + a live Signal<boolean> +
an optional label. Derived signals (hasError, errorCount,
activeErrors, errorLabels, shouldShow, announcement) are
computed() with structural equal fns so unrelated re-emissions
upstream do not cascade through descendants.
Live region
By default the directive appends a visually-hidden <span> to the
host element and writes announcement into its textContent
reactively, so an aria-live announcement fires the moment a source
toggles. The span carries role="status" (or role="alert" when
politeness is 'assertive'), aria-live, aria-atomic="true", and
aria-relevant="additions text". Visually-hidden styling is applied
inline via --cngx-sr-only-* CSS custom properties — no global
stylesheet required.
Set [autoAnnounce]="false" to take ownership of the live region in
consumer markup (for example, when routing announcements through
CDK's LiveAnnouncer service). Use [announcePoliteness] to switch
to 'assertive' for safety-critical errors or 'off' to suppress
announcements entirely while keeping the visual error surface.
<fieldset cngxErrorAggregator #agg="cngxErrorAggregator">
<span cngxErrorSource="format" [when]="email().invalid()" label="Format"></span>
<span cngxErrorSource="taken" [when]="taken()" label="Already used"></span>
@if (agg.shouldShow()) {
<ul role="alert">
@for (label of agg.errorLabels(); track label) {
<li>{{ label }}</li>
}
</ul>
}
</fieldset>Metadata#
Host#
Providers#
CNGX_ERROR_AGGREGATOR- useExisting
CngxErrorAggregator
Relationships
Depends on1
Index#
Inputs#
string | undefinedOptional name; enables programmatic lookup via CngxErrorRegistry.
undefined, { alias: 'cngxErrorAggregatorName', }"polite" | "assertive" | "off"Politeness of the auto-rendered live region. Mirrors the WAI-ARIA
aria-live value. 'polite' queues after the current utterance,
'assertive' interrupts, 'off' disables announcement (the span is
still rendered but is not announced).
'polite'When true (default), the directive appends its own visually-hidden
<span> to the host element and writes announcement into its
textContent. Set to false to take ownership of the live region in
consumer markup (e.g. when routing announcements through CDK's
LiveAnnouncer).
trueExternal scope override; falls back to ancestor CNGX_ERROR_SCOPE.
Instance Properties#
Methods#
addSource(entry: CngxErrorAggregatorSourceEntry)HostBindings#
| Binding | Expression |
|---|---|
[class.cngx-error] | shouldShow() |
[attr.aria-invalid] | shouldShow() ? "true" : "false" |