-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Nested Dynamic Components Break With ComponentFactoryResolver #10762
Comments
Plunker repro added. |
@rbj325 Have you been able to solve this ? |
@thecritic No, the only thing I've seen is to try to manually call ChangeDetectorRef.detectChanges manually but no matter where you do that the error persists. |
I have the same problem. I dynamically create a modal window and attach it to the app component. Then I dynamically create a component in the modal window. It crashes when loading the content of the modal. |
For anyone looking for a dirty hack, wrap your code in a setTimeout():
|
@jpleclerc That work around does not work for me because the dynamic form requires the control to be present when it's rendering. It did remove the change detection error though. |
Use the "AfterContentInit" lifecycle-hook to init/update your nested dynamic-component.
updated your plunker: |
@gluix Awesome, I think that's the only life cycle hook I didn't try. |
@gluix - I know that |
public ngAfterViewInit(): any { That worked! |
I got a similar problem. It is finally solved by change ngAfterViewInit to ngOnInit or add componentRef.changeDetectorRef.detectChanges() |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a ... (check one with "x")
Current behavior
When trying to render nested dynamic components via the ComponentFactoryResolver I receive an exception/error message:
browser_adapter.js:84Error: Expression has changed after it was checked. Previous value: 'CD_INIT_VALUE'. Current value: 'null'. It seems like the view has been created after its parent and its children have been dirty checked. Has it been created in a change detection hook ?
Expected/desired behavior
It should render the nested dynamic controls. This had worked until the introduction of the ComponentFactoryResolver. See: https://plnkr.co/edit/JRyqou9yC6LvSRrCR3eA?p=preview
Reproduction of the problem
Here is the plunkr recreating the issue: http://plnkr.co/edit/NzT4a7GEAB7k4yqeZrs0?p=preview
What is the expected behavior?
I should be able to render a control via ComponentFactoryResolver which in turn also renders multiple controls via ComponentFactoryResolver.
In my use case, I am rendering a form wizard made up of several dynamic components. In one of those dynamic components I am pulling fields defined in the database to render a set of user controlled fields.
What is the motivation / use case for changing the behavior?
It used to work.
Please tell us about your environment:
The text was updated successfully, but these errors were encountered: