Skip to content

NgControlStatus directive won't update with ChangeDetectionStrategy.OnPush #44976

Closed

Description

@chabb

Which @angular/* package(s) are the source of the bug?

forms

Is this a regression?

No

Description

[Component A]
[Component B (@input formControl: FormControl) <input required [formControl]='formControl'>]

Let's suppose you have a component A that pass a formControl to component, and call its setValue method at some point.
Without use onPush strategy, the value and the validation are correctly applied to the input element in the component B

But if you use onPush, the validation classes are not properly added/removed

This is the working example, without onPush strategy
If you press the button, the validation class is properly removed

Now if you use onePush ( see link below), the value is correctly propagated, but you can see that the ng-invalid class in not removed

This is a duplicate of #11563 that was closed

Currently, the way to fix it is to call cdr.markForCheck() manually.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/angular-6msgu9

Please provide the exception or error you saw

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 13.2.1

@angular/** : 13.2.1
typescript: 4.5.0
rxjs: 7.5.2

Anything else?

No response

Activity

  1. added this to the needsTriage milestone on Feb 7, 2022
  2. dylhunn commented on Feb 7, 2022

    @dylhunn
    Contributor

    This is related to #10816

  3. atscott commented on Feb 7, 2022

    @atscott
    Contributor

    Closing - this is working as expected. Angular change detection generally works off of references for inputs (some exceptions being ngFor, ngClass, etc). The FormControl input did not change so my-test is not dirty. You need to subscribe to the relevant changes of the control in your my-test and call markForCheck to mark the component dirty at the appropriate time: https://stackblitz.com/edit/angular-m6qbl9?file=src%2Fapp%2Fapp.component.html

    This is true of any input across Angular and is not isolated to the forms package.

  4. angular-automatic-lock-bot commented on Mar 10, 2022

    @angular-automatic-lock-bot

    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.

  5. locked and limited conversation to collaborators on Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions