0
我是Angular的新手。在Angular中,如何從promise中返回帶有結果和錯誤的Observable
我正在開發一些身份驗證函數,它使用promise來運行異步,並在此代碼中執行一些操作。 考慮到異步,我相信函數應該返回一個Observable。但是,如何返回Observable以及承諾的結果/錯誤?
authentication.service.ts
loginwithProvider(): <????> {
this.auth.signInWithPopup(provider)
.then(result =>{
/* do some things, such as getting data and logging */
})
.catch((error) => {
/* receive the error of the provider, do some things, such as logging */
})
return ????? <---- I want to return result and errors of the provider in an Observable to the caller function
}
login.component.ts
onLogin(){
this.request = this.authenticationService.loginWithProvider().subscribe(
(data) => {
console.log("onlogin - then success");
this.router.navigate(['/']);
},
(error) => {
console.log(" onlogin - error ", error);
show_error_to_user(error); <---- error from loginWithProvider
});
}
這是由偶然'angularfire2'? – Jeff
是的,使用angularfire2版本4進行身份驗證 – fhansen