Skip to content

angular如何主动销毁组件 #62

Open
@deepthan

Description

@deepthan

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

constructor(private element: ElementRef) {} 

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions