我試圖把頭圍在可觀察物上。我喜歡可觀測技術(shù)解決開發(fā)和可讀性問題的方式。如我所讀,好處是巨大的。HTTP和集合上的可觀察對象似乎很簡單。我如何將類似的東西轉(zhuǎn)換為可觀察的模式。這是從我的服務(wù)組件提供身份驗證的。我希望它可以像Angular2中的其他HTTP服務(wù)一樣工作-支持?jǐn)?shù)據(jù),錯誤和完成處理程序。firebase.auth().createUserWithEmailAndPassword(email, password) .then(function(firebaseUser) { // do something to update your UI component // pass user object to UI component }) .catch(function(error) { // Handle Errors here. var errorCode = error.code; var errorMessage = error.message; // ... });在這里的任何幫助將不勝感激。我唯一的替代解決方案是創(chuàng)建EventEmitter。但是我想這是在服務(wù)部分做事的一種糟糕方法
3 回答

鴻蒙傳說
TA貢獻(xiàn)1865條經(jīng)驗 獲得超7個贊
如果您使用的是RxJS 6.0.0:
import { from } from 'rxjs';
const observable = from(promise);

幕布斯6054654
TA貢獻(xiàn)1876條經(jīng)驗 獲得超7個贊
嘗試這個:
import { Observable } from "rxjs/Observable";
var subscription = Observable.fromPromise(
firebase.auth().createUserWithEmailAndPassword(email, password)
);
subscription.subscribe(firebaseUser => /* Do anything with data received */,
error => /* Handle error here */);
您可以在此處找到對fromPromise運算符的完整參考。
- 3 回答
- 0 關(guān)注
- 695 瀏覽
添加回答
舉報
0/150
提交
取消