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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…