【发布时间】:2021-05-31 20:05:57
【问题描述】:
我的身份验证服务中有此代码:
export class AuthenticationService {
private token!: string;
constructor(private http: HttpClient , private router: Router) {}
logout() {
this.http.get < {
access_token: string,
expiresIn: number
} > (BACKEND_URL + '/logout')
.subscribe(response => {
this.token = null;
this.isAuthenticated = false;
this.authStatusListener.next(false);
clearTimeout(this.tokenTimer);
this.clearAuthData();
this.router.navigate(['/']);
console.log(response);
}, error => {
console.log(error);
});
}
}
我收到了这个错误:
错误 TS2322:类型“null”不可分配给类型“字符串”。
92 this.token = null;
错误在logout()中
我改成:
this.token! = null;
但它仍然没有解决
我该如何解决?
谢谢
【问题讨论】:
标签: angular