How to re initialize sub component in angular2?

You can write your own cleanup method. But faster way (but not trully convenient) is to use *ngIf. When value is false, component is completely removed (destroyed) from page. When it is back to true it goes via regular path constructor > ngOnInit, etc. Why it is not convenient?

  • it may look ugly
  • it may require from you to trigger change detection manually

.

reinitChildComponent(): void{
    this.childVisible = false;
    this.changeDetectorRef.detectChanges();
    this.childVisible = true;
    this.changeDetectorRef.detectChanges();
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)