I need to be able to completely reload a child component. It seems the best way to to acheive this is by using a simple *ngIf with a boolean value; Set false to remove the component, and then set to true to re-initialize it, ie:
<app-child *ngIf="enabled"></app-child>
However, it seems that just doing this isn't enough to quickly remove/reinitialize the component:
reloadTree(){
this.enabled = false;
this.enabled = true; // doesn't work- child ngOnInit isn't called
}
Rather, I have to use a setTimeout before it will work:
reloadTree(){
this.enabled = false;
const self = this;
setTimeout(function(){
self.enabled = true;
}, 1);
}
I presume this is to do with the way Angular renders templates? This isn't paricularly elegant- can anyone suggest a better way to acheive what I'm trying to do here? Thanks