Custom form control (ControlValueAccesor) doesn't make parent run change detection
See original GitHub issueπ bug report
Affected Package
angular/forms
Description
Iβve created a custom file dropzone which should work correctly with ReactiveFormsModule. The problem is that after Iβve added a file, the controlβs parent (the form component) isnβt being updated. According to the valueChanges Observable, the value is being emitted correctly.
<form
(ngSubmit)="onSubmit()"
[formGroup]="form"
>
{{ form.value.file }} <-- this isn't updated until I drop a second file, then it always shows the previous file
<div
fileDropzone
formControlName="file"
></div>
</form>
Iβve noticed that if I add a custom event on the control, everything works correctly, but I shouldnβt have to do that.
<form
(ngSubmit)="onSubmit()"
[formGroup]="form"
>
{{ form.value.file }} <-- This updates correctly when listening to any custom event on the control
<div
fileDropzone
(changed)="onChange($event)"
formControlName="file"
></div>
</form>
I assumed the problem might be OnPush change detection, but even after removing it, the problem persists.
π Your Environment
Angular Version:
Angular CLI: 7.3.8
Node: 8.10.0
OS: win32 x64
Angular: 7.2.13
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.13.8
@angular-devkit/build-angular 0.13.8
@angular-devkit/build-optimizer 0.13.8
@angular-devkit/build-webpack 0.13.8
@angular-devkit/core 7.3.8
@angular-devkit/schematics 7.3.8
@angular/cdk 7.3.7
@angular/cli 7.3.8
@angular/flex-layout 7.0.0-beta.24
@angular/material 7.3.7
@angular/material-moment-adapter 7.3.7
@ngtools/webpack 7.3.8
@schematics/angular 7.3.8
@schematics/update 0.13.8
rxjs 6.4.0
typescript 3.2.2
webpack 4.29.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Custom form control couldn't get the right value from onPush ...
In ngmodel directive, setValue is called in next micro-task queue. So the parent component and the ngmodel component are not in one dirty...
Read more >How to detect changes in the bound form variable value in a ...
I've tried implementing the OnChanges interface, but the SimpleChanges object received doesn't have any reference to the bound form variable.
Read more >Never again be confused when implementing ... - InDepth.Dev
So, Angular needs a generic mechanism to stand between Angular's formControl and a native/custom form control. This is where the ControlValueAccessor objectΒ ...
Read more >Creating custom form controls in Angular (Control Value ...
This video covers Control Value Accessors, and how we can use them to minimise boilerplate markup in our forms.
Read more >Don't reinvent the wheel when implementing ... - Medium
Conclusion. If we want to make a custom form component that's compatible with Reactive Form, we need to implement ControlValueAccessor . HoweverΒ ...
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 Free
Top 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
Duplicate of https://github.com/angular/angular/issues/21780
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.