Skip to main content
cngx-src documentation

CngxErrorAggregator

DirectivePrimaryv0.1.0WCAG AA

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>

https://cngxjs.github.io/cngx/examples/#/common/interactive/error/aggregator/cngx-card-host-no-scope-errors-visible-immediately https://cngxjs.github.io/cngx/examples/#/common/interactive/error/aggregator/cngx-popover-panel-host https://cngxjs.github.io/cngx/examples/#/common/interactive/error/aggregator/material-mat-tab-label-with-error-count-badge https://cngxjs.github.io/cngx/examples/#/common/interactive/error/aggregator/native-form-scope-reveal-on-submit https://cngxjs.github.io/cngx/examples/#/ui/stepper/stepper-error-aggregation/per-step-error-badges https://cngxjs.github.io/cngx/examples/#/ui/tabs/tab-error-aggregation/per-tab-error-badges

Metadata#

Host#

Providers#

CNGX_ERROR_AGGREGATOR
useExisting CngxErrorAggregator

Relationships

Index#

Inputs#

aggregatorName#string | undefined
input()

Optional name; enables programmatic lookup via CngxErrorRegistry.

default undefined, { alias: 'cngxErrorAggregatorName', }
announcePoliteness#"polite" | "assertive" | "off"
input()

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).

default 'polite'
autoAnnounce#boolean
input()

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).

default true
input()

External scope override; falls back to ancestor CNGX_ERROR_SCOPE.

Instance Properties#

activeErrors#unknown
Readonly
this.contract.activeErrors
announcement#unknown
Readonly
this.contract.announcement
errorCount#unknown
Readonly
this.contract.errorCount
errorLabels#unknown
Readonly
this.contract.errorLabels
hasError#unknown
Readonly
this.contract.hasError
shouldShow#unknown
Readonly
this.contract.shouldShow

Methods#

removeSource#void
removeSource(key: string)
@paramkeystring

HostBindings#

BindingExpression
[class.cngx-error]shouldShow()
[attr.aria-invalid]shouldShow() ? "true" : "false"