从auth.state调用注销方法。我得到的错误是:
error TypeError:无法读取未定义的属性“管道”
@Action(Logout)
logout(ctx: StateContext<AuthStateModel>) {
return this.loginService.logout().pipe(
tap((result) => {
const state = ctx.getState();
ctx.setState({...state,
loggedInUser:undefined,
accessToken: undefined,
username: undefined,
email:undefined,
roles:undefined,
});
})
);
}
这是logOut
方法
public logout(): Observable<void> {
return this.tokenStorage.signOut();
}
这是来自signOut
的localstorage
方法
public signOut():any {
return window.sessionStorage.clear();
}
错误图像:
发布于 2021-06-22 15:51:05
您确定window.sessionStorage.clear()
有返回值吗?
clear()是一个void方法,这就是您得到该错误的原因。
通过使用console.log(window.sessionStorage.clear())
,您可以在将来简单地检查一个类似的问题,如果它返回值或未定义的值,您就会得到它。
发布于 2021-06-22 17:38:47
@Action(Logout)
logout(ctx: StateContext<AuthStateModel>) {
this.loginService.logout()
const state = ctx.getState();
ctx.setState({...state,
loggedInUser:undefined,
accessToken: undefined,
username: undefined,
email:undefined,
roles:undefined,
});
return state;
};
我用this...Thx代替了代码.我应该问另一个问题,这个above..problem实际上是(属性管道在void类型上不存在),但是我在代码中丢失了. :)
https://stackoverflow.com/questions/68086737
复制相似问题