Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnPush changeDetection not working in custom FieldTypes #2191

Closed
skrtheboss opened this issue Apr 21, 2020 · 2 comments
Closed

OnPush changeDetection not working in custom FieldTypes #2191

skrtheboss opened this issue Apr 21, 2020 · 2 comments
Labels

Comments

@skrtheboss
Copy link
Contributor

Description
If ChangeDetectionStrategy.OnPush is used in a custom FieldType, then the templateOptions which are generated via expressionProperties, do not result in a changeDetection check.

I think the problem is here, since ref.changeDetectorRef.markForCheck() does not work as expected (see angular issue).

A possible solution as suggested in this comment, would be:

if (field._componentRefs) {
    field._componentRefs.forEach(ref => {
          const changeDetectorRef = ref.injector.get(ChangeDetectorRef);
          changeDetectorRef.markForCheck()
    });
}

Minimal Reproduction
The view should dispaly the updated options, but it does not. If we remove the OnPush strategy, everything works as expected

https://stackblitz.com/edit/angular-vmswdr

Your Environment

  • Angular version: 9.1.2
  • Formly version: .5.5.15

PS
If you agree with me I can make a pull request.

Here is a StackBlitz with the fixed changeDetection.

@skrtheboss skrtheboss added the bug label Apr 21, 2020
@aitboudad
Copy link
Member

I'm ok with that change :)

@aitboudad
Copy link
Member

This issue has been fixed and released as part of v5.6.0 release.

Please let us know, in case you are still encountering a similar issue/problem.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants