1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Difference between the methods .pipe() and .subscribe() on a RXJS observable

Discussão em 'Angular' iniciado por Amadou Beye, Novembro 8, 2024 às 01:52.

  1. Amadou Beye

    Amadou Beye Guest

    I recently notice that I can return a value inside .pipe() but not inside .subscribe().

    What is the difference between these two methods?

    For example if I have this function, let's call it 'deposit', which is supposed to return the account balance, if I do this:

    deposit(account, amount){
    return this.http.get('url')
    .subscribe(res => {
    return res;
    }
    }


    It returns an observable and if I do this:

    deposit(account, amount){
    return this.http.get('url')
    .pipe(
    map(res => {
    return res;
    });
    );
    }


    It returns the account balance as expected.

    So why?

    Continue reading...

Compartilhe esta Página