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

Feature Request: valueChanges emits the initial value #61844

Copy link
Copy link
Open
@gabrielbergoc

Description

@gabrielbergoc
Issue body actions

Which @angular/* package(s) are relevant/related to the feature request?

forms

Description

When working with reactive forms, I find myself writing over and over again something like

this.form.valueChanges.pipe(startWith(this.form.value)).subscribe(...)

Could this be reworked to always emit the initial value so that this is abbreviated?

The current behavior could easily be achieved with skip(1), of course it would just move the "boilerplate" to the other use case, but I wanted to see if this is something worth discussing, or it's just me that uses the former case much more frequently than the latter (or even if I'm missing some easier way to achieve the behavior that I want).

Proposed solution

New usage:

this.form.valueChanges.subscribe(/* subscription receives all values starting with the initial value of the form */)
this.form.valueChanges.pipe(skip(1)).subscribe(/* how to get current behavior */)

Alternatives considered

I've seen some discussion about adding signals to forms, I think it would be a great alternative, because in a lot of cases, I'm using the valueChanges with toSignal, so this would already save a lot of repetitive code.

Metadata

Metadata

Assignees

No one assigned

    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.