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/formsIs this a regression?
I don't think soDescription
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:
- Created 3 years ago
- Reactions:2
- Comments:10 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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?@ameryousuf you can work on this, I am a bit tight on time