Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add modelFrom(writableSignal) Function to create an input/output binding from a writableSignal #61419

Copy link
Copy link
Closed as duplicate of#60243
@manudss

Description

@manudss
Issue body actions

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

import { modelFrom, signal  } from '@angular/core';

@Component(...)
class MyComponent  {
   mySignalStore = inject(MySignalStore);

   myModel = modelFrom(mySignalStore);
}

// In a component template
<my-compoent [(myModel)]="value">

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimeIssues related to the framework runtimecore: reactivityWork related to fine-grained reactivity in the core frameworkWork related to fine-grained reactivity in the core frameworkcross-cutting: signals

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.