ChangeDetector and NgForm false valid on template using OnPush and NgModel
See original GitHub issueπ bug report
Affected Package
FormsModuleIs this a regression?
noDescription
When using OnPuh
startegy, NgForms
initially shows a false postive on the Template
valid status
even if the form is invalid (like when it has a required input).
If we subscribe to statusChange
on the model we get the invalid state within the stream, but still not in the view.
Iβve opened this issue because I think NgModel
should act like @Input
and trigger change detection automatically when it has changes.
The change detection is triggered when the user interacts with the form through the DOM
or the NgModel
changes the value, but the ChangeDetector is failing to detect the initial state on the Template using OnPush
.
π¬ Minimal Reproduction
https://stackblitz.com/edit/angular-jvwfw3
π Your Environment
Angular Version:
Angular CLI: 9.1.1
Node: 10.16.2
OS: linux x64
Angular: 9.1.1
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.901.1
@angular-devkit/build-angular 0.901.1
@angular-devkit/build-optimizer 0.901.1
@angular-devkit/build-webpack 0.901.1
@angular-devkit/core 9.1.1
@angular-devkit/schematics 9.1.1
@angular/cdk 9.2.0
@angular/flex-layout 9.0.0-beta.29
@angular/material 9.2.0
@ngtools/webpack 9.1.1
@schematics/angular 9.1.1
@schematics/update 0.901.1
rxjs 6.5.5
typescript 3.8.3
webpack 4.42.0
Anything else relevant?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Angular OnPush Change Detection - Avoid Common Pitfalls
An OnPush change detector gets triggered in a couple of other situations other than changes in component Input() references, it also getsΒ ...
Read more >How Validators work with change detection strategy "onPush ...
After create row I see "Valid status is true". But it should be false. Valid status changed after form clicking, but data not...
Read more >ChangeDetectorRef - Angular
Base class that provides change detection functionality. A change-detection tree collects all views that are to be checked for changes. Use the methods...
Read more >Chapter 11. Validating forms - Angular Development with ...
Both fields are requiredβotherwise, the form isn't valid. You shouldn't even allow submitting this form until the user has filled out all required...
Read more >@angular-package/change-detection NPM | npm.io
Uses ApChangeDetectorClass to handle change detection. ... OnPush in component. ... detection with specified value true or false. public changeDetector:Β ...
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
@souhailharrati, thank you for your workaround!
Even having ways of working around this issue, it is still an issue. The state of both components are the same at the same time, but
OnPush
doesnβt reflects the state as it should do.My workaround was enabling
Default
mode on that specific component and wait for this issue to be solved.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.