Angular Dynamic component with ngComponentOutlet not fully rerendered

72 Views Asked by At

When using *ngComponentOutlet to render dynamic components in Angular, everything works fine until you do not switch component type. If the component type you pass to the *ngComponentOutlet directive is the same as the previous created one, only the inputs are updated but the component lifeCycle is not replayed.

This is an issue for me since I need to execute some conditions and code blocks in constructor or ngOnInit hook.

The only workaround I found for now is when I need to refresh the component, I first pass null to the variable containing the type of the component so that the directive destroy the previous instance (made automatically) and then reassign via setTimeout function the component type in the variable with different inputs.

My question is: is there a better way to do this ?

0

There are 0 best solutions below