question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FormControl valueChanges should emit null instead of previous value on control.disabled()

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/forms

Is this a regression?

I don't think so

Description

when a control is disabled it’s new value is null, bit the valueChanges event doesn’t emit with null, but rather with the previous value. This is inconsistent IMHO.

It is specially problematic when using nested forms. My ugly workaround looks like this:

this.editForm.valueChanges.subscribe(value => this.value = this.editForm.disabled ? null : value);

Once this is confirmed as a bug I would really like to contribute with the simple code change and relative tests, please allow me to do so. Thanks πŸ˜ƒ

πŸ”¬ Minimal Reproduction

https://stackblitz.com/edit/angular-ivy-fjxciy

🌍 Your Environment

Angular Version:



Angular CLI: 9.0.4
Node: 10.16.3
OS: linux x64

Angular: 9.0.4
... animations, cli, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.900.4
@angular-devkit/core         9.0.4
@angular-devkit/schematics   9.0.4
@angular/cdk                 9.0.1
@ngtools/webpack             9.0.4
@schematics/angular          9.0.4
@schematics/update           0.900.4
rxjs                         6.5.3
typescript                   3.7.5
webpack                      4.41.2


Anything else relevant?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
mlc-mlapiscommented, Jun 28, 2020

Reading this conversation, it reminds me that the base of this is probably the non-existence of readonly property, as it has been since the issue, as #11447, isn’t it?

1reaction
yelhouticommented, Mar 16, 2022

@ameryousuf you can work on this, I am a bit tight on time

Read more comments on GitHub >

github_iconTop Results From Across the Web

Form control valueChanges gives the previous value
valueChanges is an Observable so you can pipe pairwise to get the previous and next values in the subscription. // No initial value....
Read more >
ValueChanges in Angular Forms - TekTutorialsHub
The ValueChanges is an event raised by the Angular forms whenever the value of the FormControl, FormGroup, or FormArray changes.
Read more >
FormControl - Angular
FormControl takes a single generic argument, which describes the type of its value. This argument always implicitly includes null because the control can...
Read more >
Angular Reactive Forms: Tips and Tricks | by Netanel Basal
For example, if you have an input that is bound to a form control, ... a control's disable() or enable() methods, Angular triggers...
Read more >
Is there any way to access form control old value so I can ...
Hi, I am trying to call a loadComponents function whenever my project value changes, but Angular emits the event even if I disable/enableΒ ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found