伙计们,在下面的角度2应用场景中需要你的帮助.我有注销链接,需要在AuthService中调用方法.
<li><a [routerLink]="['/logout']"><span class="glyphicon glyphicon-log-out" aria-hidden="true"></span> Logout</a></li>
Run Code Online (Sandbox Code Playgroud)
AuthService中的方法:
//logout
logout() {
this.isUserLoggedin = false;
}
Run Code Online (Sandbox Code Playgroud)
怎么做到这一点?我不想创建一个仅用于调用注销的新组件.感谢您的帮助.
ste*_*ddy 20
我想知道同样的事情,但我最终创建了一个带有空白模板的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']);
}
}
Run Code Online (Sandbox Code Playgroud)
app.routes.ts
{ path: 'logout', component: LogoutComponent}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19677 次 |
| 最近记录: |