deepthan/blog-angular

angular如何主动销毁组件

deepthan opened this issue · 0 comments

使用remove函数,它不会触发组件的生命周期,还得手动调用ngOnDestroy

constructor(private element: ElementRef) {} 

// 你要销毁的时候调用它
triggerDestroy(){
    this.element.nativeElement.remove(); 
    this.ngOnDestroy() 
}