Advanced Examples
Advanced validation remains easier to reason about when policies stay deterministic and workflow code owns lifecycle decisions.
Nested model paths
Use dotted paths for nested values such as shipping.address.city. Keep the same path in summaries, NgRx selectors, and form-control mappings.
Asynchronous validation
Rules may return observables for server or data-source checks. validateAll() waits for asynchronous validators before it updates dependent required state and emits completion.
Debounce and cancellation belong in the application boundary when validation is triggered by rapid user input.
Dynamic forms
Generated fields can build a policy at runtime. Use replacePolicy() when the current configuration changes, and unregister the policy when the feature is destroyed.
Conditional required fields
Dependencies can activate a rule based on another model value. Call updateConditionalRequiredFields() through normal validation execution so required indicators remain aligned with the active policy.
Multi-section workflows
Evaluate one section during focused interaction and the complete policy group during submit. This provides useful local feedback without losing an authoritative full-workflow result.
Error handling
Subscribe with an error handler for validators that depend on external services. Keep transport failures distinct from ordinary validation failures so users receive the right recovery action.