我試圖把頭圍在可觀察物上。我喜歡可觀測技術解決開發和可讀性問題的方式。如我所讀,好處是巨大的。HTTP和集合上的可觀察對象似乎很簡單。我如何將類似的東西轉換為可觀察的模式。這是從我的服務組件提供身份驗證的。我希望它可以像Angular2中的其他HTTP服務一樣工作-支持數據,錯誤和完成處理程序。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; // ... });在這里的任何幫助將不勝感激。我唯一的替代解決方案是創建EventEmitter。但是我想這是在服務部分做事的一種糟糕方法
3 回答

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

幕布斯6054654
TA貢獻1876條經驗 獲得超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 關注
- 696 瀏覽
添加回答
舉報
0/150
提交
取消