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.

ChangeDetector and NgForm false valid on template using OnPush and NgModel

See original GitHub issue

🐞 bug report

Affected Package

FormsModule

Is this a regression?

no

Description

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?

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
vinagreticommented, Apr 22, 2020

@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.

0reactions
angular-automatic-lock-bot[bot]commented, Dec 10, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

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