Add modelFrom(writableSignal) Function to create an input/output binding from a writableSignal
#61419
Labels
area: core
Issues related to the framework runtime
core: reactivity
Work related to fine-grained reactivity in the core framework
cross-cutting: signals
Milestone
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
Currently, Angular provides a way to create models for two-way data binding using [(ngModel)] with new signal method
model()
. However, when using writableSignal from another service or library (such as a signal store or functions like linkedQueryParams or injectLocalStorage from ngxtension), there is no direct way to bind these signals to component inputs/outputs without manually synchronizing the model and the signal.The proposed
modelFrom(writableSignal)
function would allow developers to create a model from a writableSignal, enabling seamless two-way data binding between the signal and component inputs/outputs. This would be analogous to the existing outputFromObservable function but for two-way binding.Proposed solution
Introduce a new function
modelFrom(writableSignal)
in @angular/core that takes a writableSignal and returns a model that can be used with[(ngModel)]
for two-way data binding. This function would handle the synchronization between the signal and the model, ensuring that updates to either are reflected in both.Example Usage
Alternatives considered
Manual Synchronization: Developers can manually synchronize the model and the signal by subscribing to changes in both and updating the other accordingly. This approach is error-prone and requires boilerplate code.
The proposed modelFrom(writableSignal) function provides a clean, built-in solution that aligns with Angular's existing patterns and reduces boilerplate code.
The text was updated successfully, but these errors were encountered: