I am using some back-end rendered templates in Angular 4 app. And after login I need to reload these templates. Could please someone help with this? I tried something like
import { Component, Compiler } from '@angular/core';
this.compiler.clearCache();
this.compiler.compileModuleAndAllComponentsAsync(SharedModule);
And I see, that template reloads in the Network tool, but Angular component does't render.
I could not find how to reload a template myself, but I found a workaround:
Using DoCheck().
Explanation:
onInit()
and store that behavior in a directive or method. DoCheck()
I am constantly listening to model changing and as soon as the model that I am interested on changes, I trigger that directive or method with the functionality of the component. And therefore, the component sort of rerenders.I implemented this here: Angular2: rendering / reloading a component's template
See my answer, I know it's long, but basically what I did was rerender my menu component when I wanted.
I hope this can be useful... Good Luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With