createFieldSync
projects/forms/field/field-sync.ts
Description#
Bidirectional Field <-> control value sync via CngxFormFieldPresenter.
Two effect()s, each reading the opposite branch inside untracked() with
valueEquals as the cycle break - the canonical bridge every model()-based
cngx control reuses instead of re-implementing field write-back. Both the
field and the control's model() are writable sources of truth, so this is
coordination, not a single computed(). Requires an injection context;
no-op without a surrounding cngx-form-field.
Keeps the create* prefix despite calling inject() in its body: it is a
blessed exception (see architecture-summary, mirrors adaptFormControl),
not an oversight. The name is also the public @cngx/forms/select export;
renaming would break that contract.
createFieldSync<number>({
componentValue: this.value,
valueEquals: Object.is,
coerceFromField: (v) => (typeof v === 'number' ? v : 0),
});