Skip to main content
1893 votes
35 answers
852k views

What is the difference between Promises and Observables?

What is the difference between Promise and Observable in Angular? An example on each would be helpful in understanding both the cases. In what scenario can we use each case?
Rohit's user avatar
  • 19k
1066 votes
28 answers
441k views

Angular/RxJS When should I unsubscribe from `Subscription`

When should I store the Subscription instances and invoke unsubscribe() during the ngOnDestroy life cycle and when can I simply ignore them? Saving all subscriptions introduces a lot of mess into ...
Sergey Tihon's user avatar
  • 12.7k
1034 votes
14 answers
684k views

What is the difference between BehaviorSubject and Observable?

I'm looking into the design patterns of RxJS, and I do not understand the difference between BehaviorSubject and Observable. From my understanding, BehaviorSubject can contain a value that may change. ...
Kevin Mark's user avatar
  • 10.4k
465 votes
10 answers
333k views

What is the difference between Subject and BehaviorSubject?

I'm not clear on the difference between a Subject and a BehaviorSubject. Is it just that a BehaviorSubject has the getValue() function?
Mike Jerred's user avatar
  • 10.4k
431 votes
9 answers
391k views

Convert Promise to Observable

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 ...
Krishnan Sriram's user avatar
369 votes
14 answers
150k views

Is it necessary to unsubscribe from observables created by Http methods to avoid memory leaks?

Do you need to unsubscribe from Angular 2 http calls to prevent memory leak? fetchFilm(index) { var sub = this._http.get(`http://example.com`) .map(result => result.json()) ...
born2net's user avatar
  • 24.9k
354 votes
22 answers
118k views

What is the correct way to share the result of an Angular Http network call in RxJs 5?

By using Http, we call a method that does a network call and returns an http observable: getCustomer() { return this.http.get('/someUrl').map(res => res.json()); } If we take this observable ...
Angular University's user avatar
348 votes
19 answers
267k views

Angular HTTP GET with TypeScript error http.get(...).map is not a function in [null]

I have a problem with HTTP in Angular. I just want to GET a JSON list and show it in the view. Service class import {Injectable} from "angular2/core"; import {Hall} from "./hall"; import {Http} ...
Claudiu Matei's user avatar
345 votes
11 answers
403k views

How to get current value of RxJS Subject or Observable?

I have an Angular 2 service: import {Storage} from './storage'; import {Injectable} from 'angular2/core'; import {Subject} from 'rxjs/Subject'; @Injectable() export class SessionStorage extends ...
williamsandonz's user avatar
343 votes
10 answers
299k views

Subscribe is deprecated: Use an observer instead of an error callback

When I run the linter it says: subscribe is deprecated: Use an observer instead of an error callback Code from this angular app: this.userService.updateUser(data).pipe( tap(() => {bla ...
ismaestro's user avatar
  • 8,167
271 votes
15 answers
303k views

Return an empty Observable

The function more() is supposed to return an Observable from a get request export class Collection { public more = (): Observable<Response> => { if (this.hasMore()) { return this....
Murhaf Sousli's user avatar
270 votes
8 answers
155k views

Subject vs BehaviorSubject vs ReplaySubject in Angular

I've been looking to understand those 3: Subject BehaviorSubject ReplaySubject I would like to use them and know when and why, what are the benefits of using them and although I've read the ...
user avatar
255 votes
6 answers
281k views

take(1) vs first()

I found a few implementation of AuthGuards that use take(1). In my project, I used first(). Do both work the same way? import 'rxjs/add/operator/map'; import 'rxjs/add/operator/first'; import { ...
Calvin Ferrando's user avatar
243 votes
11 answers
99k views

'of' vs 'from' operator

Is the only difference between Observable.of and Observable.from the arguments format? Like the Function.prototype.call and Function.prototype.apply? Observable.of(1,2,3).subscribe(() => {}) ...
xiaoke's user avatar
  • 3,431
238 votes
7 answers
149k views

Create one-time subscription

I need to create a subscription to an Observable that is immediately disposed of when it is first called. Is there something like: observable.subscribeOnce(func); My use case, I am creating a ...
Berkeley Martinez's user avatar

15 30 50 per page
1
2 3 4 5
1413