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.

Using a shared FormComponent more than twice throws `ExpressionChangedAfterItHasBeenCheckedError`

See original GitHub issue

⭐’ed it 😄

Description We have a general component (lets call it FormComponent) which implements a form with a formly-form. This component is used to add some HostListeners. Back in the days we had to add FormlyFormBuilder.buildForm to the ngOnInit of that component to prevent getting the ExpressionChangedAfterItHasBeenCheckedError exception (removing this seems not to resolve the new issue and it also brings this previous scenario back).

We have avoided updating this dependency since we got the same exception after the release of v5.10.27. It happens when we add our FormComponent more than 2 times in the same template, using the same form but different fields at least once.

It’s been a while and I wanted to keep this dependency up to date as well, so I tried updating it again to the latest version. Unfortunately we still got the same exception.

Minimal Reproduction Can be found at: https://github.com/sjoulbak/formly-bug-multi-form

Run yarn run test to see the exception.

Your Environment

  • Angular version: 14.1.0
  • Formly version: 5.12.6

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
aitboudadcommented, Aug 26, 2022

Do you have another suggestion?

will check!

0reactions
aitboudadcommented, Nov 14, 2022

I see, so the root issue is passing the same form instance to multi-component causes an update in the form state during the same cycle:

  • first render: form state updated to valid
  • second render: form state updated to invalid

What I’d suggest is if possible to use multi formly-field instead, to have an idea check the following example https://formly.dev/docs/examples/advanced/tabs/

Read more comments on GitHub >

github_iconTop Results From Across the Web

ExpressionChangedAfterItHasBe...
This error indicates a real problem in your application, therefore it makes sense to throw an exception. In ...
Read more >
mat-button ExpressionChangedAfterItHasBeenCheckedError
When the checkbox is checked, ExpressionChangedAfterItHasBeenCheckedError is thrown. If mat-button on the submit button is removed, the error is not thrown.
Read more >
Everything you need to know about the ... - InDepth.Dev
Everything you need to know about the `ExpressionChangedAfterItHasBeenCheckedError` error. This article explains the underlying causes of the error and the ...
Read more >
Angular Debugging "Expression has changed": Explanation ...
Learn a complete explanation about ExpressionChangedAfterItHasBeenCheckedError: why it occurs, how to troubleshoot it and how to fix it.
Read more >
Expression Has Changed After It Was Checked — Angular ...
Once the B component is checked the current digest loop is finished. Yet it has and so Angular throws the error ExpressionChangedAfterItHasBeenCheckedError ....
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