【发布时间】:2020-06-02 19:25:40
【问题描述】:
您好,我已使用锚标记在新选项卡中打开 routerLink。现在,如果我单击注销,新选项卡中的 routerLink 保持不变,如果有任何 API 命中,则 routerLink 重定向到登录页面。但我希望在我注销后立即关闭所有选项卡,因为其他路由器页面在屏幕上没有标题。
Header.component.ts:
public logout() {
this.authservice.logOutSuccess(true);
this.router.navigate(["/login"]);
this.cookieService.delete(TPIConstants.AUTH_TOKEN);
}
在标题组件中,如果我点击注销,我将清除 cookie,因此屏幕将重定向到登录页面。
但是在登陆页面中,我添加了新按钮,当我点击它时,它会在新选项卡中打开路由器,
Landing.html:
<a class="btn btn-light" target="_blank" [routerLink]="['/profile']"> Add New</a>
个人资料屏幕现在在新标签中打开。
所以,我使用了一个名为 auth.service 的通用服务,其中我使用了主题
auth.service.ts:
public detectLogOutSubject = new Subject<any>();
logOutConfirmed$ = this.detectLogOutSubject.asObservable();
logOutSuccess(value) {
this.detectLogOutSubject.next(value);
}
所以当我点击注销时,它会来到 authservice 并触发此事件,并且在配置文件页面中我在构造函数方法中这样写
profile.component.ts: 和 app.component.ts
constructor(){
this.subscription = this.authService.logOutConfirmed$.subscribe(
res => {
alert(res)
});
}
个人资料.html:
<div>
<button class="btn btn-secondary" onclick="window.close();" title="Close Window">
<i class="fas fa-times fa-1x"></i>
</button>
</div>
在配置文件 html 中,我有上面的 div 部分,如果该点击也被触发,它将关闭选项卡,但我也无法从注销功能获取事件到配置文件屏幕/app.component,我很震惊, 不知道怎么做
【问题讨论】:
标签: javascript angular