在从共享标头组件调用注销按钮之前调用组件的 ngOndestroy



当我从特定组件单击应用程序的共享标头注销按钮时,首先调用注销函数,然后调用组件ngOnDestroy。

如何在调用注销函数之前调用 ngOnDestroy

header.component.ts
  logout() {
     //CALLING FIRST
  }
specific.component.ts
 ngOnDestroy(){
   //CALLING AFTER LOGOUT
 }

header.component.html
<logout button>
<specific.component.html
<header></header>
实际上这是

正确的行为,但您可以尝试使用这样的东西:

在父级中,包括标头和特定:

show: boolean = true;
onLogout() {
    this.show = false;
}

在标题中...TS:

@Output() onLogout: EventEmitter<any> = new EventEmitter<any>();
logout() {
    this.onLogout.emit('');
    // your logout operations;
}

在父....html:

<specific *ngIf="show" ...>

这种方式在注销操作之前销毁特定组件;附言没有尝试过这个,只是一个建议

最新更新