resolveDynamicValue
@ng-forge/dynamic-forms
Normalises a {@link DynamicValue} into a Signal<T>.
Accepts a static value, a Signal<T>, or an Observable<T>. The result
is a Signal<T> that reactively reflects the current value, suitable
for direct use in Angular templates.
Static values yield a computed that always returns the same constant —
preferable to wrapping in because the computed never causes
change-detection invalidation.signal()
Pass an injector when calling outside an Angular injection context
(e.g., from inside a computed). toSignal needs a DestroyRef to
unsubscribe — without an injector it falls back to inject(DestroyRef),
which throws when called outside injection context.
Signature
function resolveDynamicValue<
T
>(
value: DynamicValue<T> | undefined,
fallback: T,
injector?: Injector | undefined
): Signal<T>Type Parameters
| Name | Constraint | Default | Description |
|---|---|---|---|
T | - | - | - |
Parameters
| Name | Type | Description |
|---|---|---|
value | DynamicValue<T> | undefined | - |
fallback | T | - |
injector? | Injector | undefined | - |
Returns
Signal<T>
Examples
const isHidden = resolveDynamicValue(addon().hidden, false);
// template: \@if (isHidden()) { ... }packages/dynamic-forms/src/lib/utils/dynamic-value/resolve-dynamic-value.ts:28