我可以用什么来刷新 observable 而不是 switchMap()?

问题描述

我以 angular 刷新浏览器时注销。 我使用 Authentication 标头处理了我的登录请求和用户请求,因此我确实使用了 observable 和 switchMap 。 现在我的问题是每次使用 switchMap 时,我的 observable 都会刷新,因此用户观察者会发生变化。 我应该怎么做才能获得我的项目列表而不使用 switchMap() ?

 getProjectByToken(): Observable<ProjectList> {
const auth = this.getAuthFromLocalStorage();
if (!auth || !auth.token) {
  return of(undefined);
}
this.isLoadingSubject.next(true);
return this.authHttpService.getTableData(auth.token).pipe(
  map((list: ProjectList) => {
    if (list) {
      console.log(new BehaviorSubject<ProjectList>(list))
      this.currentListSubject = new BehaviorSubject<ProjectList>(list);
    } else {
      console.log(list)
    }
    console.log(list)
    return list;
  }),switchMap(() => this.getLogToken()),finalize(() => this.isLoadingSubject.next(false))
);

}

这是我处理标头请求和设置本地存储的方法

     getProject(){
   console.log(this.currentBtnSubject.asObservable())
   return this.currentListSubject.asObservable()  
  }

我在我的项目组件中使用了这个方法并且我订阅了它

login(email: string,password: string): Observable<usermodel> {
this.isLoadingSubject.next(true);

return this.authHttpService.login(email,password).pipe(
  map((auth: AuthModel) => {
    const result = this.setAuthFromLocalStorage(auth);
    console.log(result)
    return result;
  }),switchMap(() => this.getUserByToken()),switchMap(() => this.getProjectByToken()),catchError((err) => {
    console.error('err',err);
    return of(undefined);
  }),finalize(() => this.isLoadingSubject.next(false))
);

}

在这里,当我使用 switchmap 方法时,没有它,列表根本不会显示

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)