CngxAsync
projects/common/data/async/async.directive.ts
Import#
import { CngxAsync } from '@cngx/common/data'
Description#
Structural directive for async state-driven content rendering.
Renders different views based on the current CngxAsyncState status:
- loading (first load) → skeleton template (or nothing)
- success + has data → content template with typed data
- success + empty → empty template (or nothing)
- error (first load) → error template (or nothing)
- refreshing / loading (with data) → content template (old data stays visible)
- error (with data) → content template (old data stays visible)
Minimal - just content
<ul *cngxAsync="residents; let data">
@for (r of data; track r.id) { <li>{{ r.name }}</li> }
</ul>With custom templates
<ul *cngxAsync="residents; let data; skeleton: skelTpl; empty: emptyTpl; error: errTpl">
@for (r of data; track r.id) { <li>{{ r.name }}</li> }
</ul>
<ng-template #skelTpl>
@for (i of [1,2,3]; track i) { <li class="skeleton-line"></li> }
</ng-template>
<ng-template #emptyTpl>
<li>No residents found.</li>
</ng-template>
<ng-template #errTpl let-err>
<li>Error: {{ err }}</li>
</ng-template>Metadata#
Index#
Inputs#
TemplateRef | undefined Optional empty template shown when data is empty after success.
TemplateRef<{ $implicit: unknown }> | undefinedOptional error template shown on error during first load. Context: { $implicit: error }.
TemplateRef | undefined Optional skeleton template shown during first load.
Methods#
CngxAsyncContextngTemplateContextGuard(_dir: CngxAsync<T>, _ctx: unknown)Type guard for template type inference.
unknown