RootFormRegistryService
| Decorators: | @Injectable |
Registry service that maintains references to root form fields. This provides a type-safe way to access root form values from child fields without relying on internal Angular Forms API navigation.
This service should be provided at the component level to ensure proper isolation between different form instances.
IMPORTANT: This registry supports two registration patterns:
- registerFormValueSignal() - Register the SOURCE signal BEFORE form creation This allows logic functions to read form values during schema evaluation.
- registerRootForm() - Register the FieldTree AFTER form creation This provides access to the full form structure.
For cross-field logic to work correctly, registerFormValueSignal() should be called BEFORE the form() call.
Methods
clear() |
|---|
Clears all registered forms. Useful for testing. |
Presentation |
Returnsvoid |
getFormContext() | ||||||
|---|---|---|---|---|---|---|
Gets form context by id. | ||||||
Presentation | ||||||
Parameters
ReturnsRecord<string, unknown> |
getFormValue() | ||||||
|---|---|---|---|---|---|---|
Gets the form value, preferring the direct signal if available. This method tries in order:
Reading from signals creates reactive dependencies, so computeds will re-evaluate when form values change. | ||||||
Presentation | ||||||
Parameters
ReturnsRecord<string, unknown> |
getFormValueSignal() | ||||||
|---|---|---|---|---|---|---|
Gets the registered form value signal by id. This allows direct access to the source signal, which can be read reactively to get form values. | ||||||
Presentation | ||||||
Parameters
ReturnsSignal<Record<string, unknown>> | undefined |
getRegisteredFormIds() |
|---|
Gets all registered form IDs. |
Presentation |
Returnsstring[] |
getRootForm() | ||||||
|---|---|---|---|---|---|---|
Gets a registered root form field by id. IMPORTANT: This method reads from a signal, which means any computed signal that calls this method will automatically re-evaluate when the form is registered or updated. | ||||||
Presentation | ||||||
Parameters
ReturnsFieldTree<unknown> | undefined |
registerFormContext() | |||||||||
|---|---|---|---|---|---|---|---|---|---|
Registers form context (field paths and metadata) for a specific form. This can be used to store additional context information. | |||||||||
Presentation | |||||||||
Parameters
Returnsvoid |
registerFormValueSignal() | |||||||||
|---|---|---|---|---|---|---|---|---|---|
Registers the form value signal BEFORE form creation. This is the recommended pattern for cross-field logic:
This allows logic functions to access form values during schema evaluation. | |||||||||
Presentation | |||||||||
Parameters
Returnsvoid |
registerRootForm() | |||||||||
|---|---|---|---|---|---|---|---|---|---|
Registers a root form field with an optional identifier. If no id is provided, uses 'default' as the key. This triggers reactive updates for any computed signals that depend on getRootForm(). | |||||||||
Presentation | |||||||||
Parameters
Returnsvoid |
unregisterForm() | ||||||
|---|---|---|---|---|---|---|
Unregisters a form and its context. This should be called when a form component is destroyed to prevent memory leaks. | ||||||
Presentation | ||||||
Parameters
Returnsvoid |