Convert Promise to Observable

Discussão em 'Angular' iniciado por Krishnan Sriram, Maio 28, 2025.

  1. I am trying to wrap my head around observables. I love the way observables solve development and readability issues. As I read, benefits are immense.

    Observables on HTTP and collections seem to be straightforward. How can I convert something like this to observable pattern?

    This is from my service component to provide authentication. I'd prefer this to work like other HTTP services in Angular2 - with support for data, error and completion handlers.

    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;
    // ...
    });


    The only alternative solution I had was to create EventEmitters. But I guess that's a terrible way to do things in services section

    Continue reading...

Compartilhe esta Página