以角度2注销链接
发布时间:2020-12-17 07:20:05 所属栏目:安全 来源:网络整理
导读:伙计们, 在角度2应用场景下需要你的帮助. 我有注销链接,需要在AuthService中调用方法. lia [routerLink]="['/logout']"span class="glyphicon glyphicon-log-out" aria-hidden="true"/span Logout/a/li AuthService中的方法: //logout logout() { this.isUs
伙计们,
在角度2应用场景下需要你的帮助. 我有注销链接,需要在AuthService中调用方法. <li><a [routerLink]="['/logout']"><span class="glyphicon glyphicon-log-out" aria-hidden="true"></span> Logout</a></li> AuthService中的方法: //logout logout() { this.isUserLoggedin = false; } 怎么做到这一点?我不想创建一个仅用于调用注销的新组件.
我想知道同样的事情,但我最终创建了一个带有空白模板的LogoutComponent,并在此之后重定向用户登录.基于按钮的注销功能有效,但我想要一个注销路由链接.
LogoutComponent.ts @Component({ template: '' }) export class LogoutComponent implements OnInit { constructor(private _authService: AuthService,private router: Router) {} ngOnInit() { this._authService.logout(); this.router.navigate(['login']); } } app.routes.ts { path: 'logout',component: LogoutComponent} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |