Angular 2 (4) reload template from source code

I use some ready-made templates in an Angular 4 application. And after logging in, I need to reload these templates. Can anyone help with this? I tried something like

import { Component, Compiler } from '@angular/core'; this.compiler.clearCache(); this.compiler.compileModuleAndAllComponentsAsync(SharedModule); 

And I see that this template is reloading in the Network tool, but the Angular component is not showing.

+5
source share
1 answer

I could not find how to reload the template myself, but I found a workaround:

Using DoCheck () .

Explanation:

  • I basically understand how my component works, what it does onInit() and saves this behavior in a directive or method.
  • With DoCheck() I constantly listen to model changes, and as soon as the model I'm interested in changes, I run this directive or method with the functionality of the component. And, therefore, the component view of the Raiders.

I implemented this here: Angular2: rendering / reloading a component template

Look at my answer, I know this for a long time, but basically what I did was rename my menu component when I wanted.

Hope this can be helpful ... Good luck!

+1
source

All Articles