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?