【发布时间】:2020-05-26 04:37:22
【问题描述】:
我有一个关于如何将 Observable 返回到外部承诺的问题。我的 effects.ts 中有以下内容:
@Effect()
login$: Observable<Action> = this.actions$.pipe(
ofType(UserActions.LOGIN),
switchMap((action: UserActions.LoginAction) => {
this.db.auth.signInWithEmailAndPassword(action.payload.email, action.payload.password).then(data => {
this.db.auth.currentUser.getIdToken().then(reply => {
return this.http.post(environment.apiUrl+'/api/login', { token: reply }).subscribe(response => {
if (response['valid'] === 'true') {
localStorage.setItem('token', JSON.stringify(reply));
this.router.navigate(['dash']);
}
});
});
}).catch(err => {
console.log('signIn failed: ' + err.message);
});
})
);
现在,我的总体目标是简单地登录 FireBase 以获取 ID 令牌并向后端提交发布请求。如果响应返回属性有效“true”,则继续导航到“dash”模块。
但是,我的问题是:
'(action: UserActions.LoginAction) => void' 类型的参数不能分配给'(value: LoginAction, index: number) => ObservableInput' 类型的参数。 类型 'void' 不可分配给类型 'ObservableInput'.ts(2345)
我相信这是因为我将我的回报声明放在了外部承诺中。但我不知道如何让它正确返回,因为 Firebase 使用 Promise,而 NgRX 使用 Observables!我正在尝试从承诺中返回一个 Observable...谢谢
【问题讨论】:
-
首先有承诺,其次你没有返回一个动作
标签: angular firebase promise observable ngrx