【发布时间】:2016-08-18 22:52:58
【问题描述】:
我正在使用 angular2 和 @ngrx/store 制作一个应用程序...我是 rxjs 的新手,并以一种反应式的方式思考...真的很苦恼如何链接可观察对象。
我有一个身份验证效果...目前看起来像
@Effect() authenticate$ = this.updates$
.whenAction(AuthActions.AUTHENTICATE_REQUEST)
.switchMap(update => this.api.post('/authenticate', update.action.payload)
.map((res:any) => this.authActions.authenticateSuccess(res.json()))
.catch((err:any) => Observable.of(this.authActions.authenticateError(err)))
);
我想做的是在请求成功时链接两个额外的操作。
- 使用
this.router.navigate(['/'])成功后导航到“主页”。 - 将凭据存储在 LocalStorage 服务
this.authService.store(credentials)
我需要做什么才能将这些操作合并到流中?
【问题讨论】:
-
您正在调度一个 authenticateSuccess 操作,因此您应该以另一种效果来处理它。当您有多种身份验证方式时,这尤其有用。