Questions tagged [rxjs]

A JavaScript library that uses observables to work with reactive programming that deals with asynchronous data calls, callbacks and event-based programs.

Resources

Related tags

20563 questions
1848
votes
34 answers

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
  • 18,575
  • 3
  • 11
  • 9
1020
votes
29 answers

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 component code. HTTP Client Guide ignore…
1010
votes
14 answers

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. It can be subscribed to and subscribers can…
Kevin Mark
  • 10,173
  • 3
  • 10
  • 10
434
votes
10 answers

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
  • 9,551
  • 5
  • 22
  • 42
403
votes
9 answers

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 straight forward. How can I convert something like…
Krishnan Sriram
  • 5,037
  • 5
  • 21
  • 31
353
votes
11 answers

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

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()) .map(json => { …
born2net
  • 24,129
  • 22
  • 65
  • 104
348
votes
22 answers

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 and add multiple subscribers to it: let network$ =…
Angular University
  • 42,341
  • 15
  • 74
  • 81
348
votes
19 answers

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} from "angular2/http"; @Injectable() export class…
Claudiu Matei
  • 4,091
  • 3
  • 19
  • 33
322
votes
13 answers

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 Storage { private _isLoggedInSource = new…
williamsandonz
  • 15,864
  • 23
  • 100
  • 186
319
votes
10 answers

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 bla bla}) ).subscribe( …
ismaestro
  • 7,561
  • 8
  • 37
  • 50
263
votes
15 answers

Return an empty Observable

The function more() is supposed to return an Observable from a get request export class Collection { public more = (): Observable => { if (this.hasMore()) { return this.fetch(); } else { // return empty observable …
Murhaf Sousli
  • 12,622
  • 20
  • 119
  • 185
252
votes
8 answers

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 documentation, watched tutorials and searched google I've…
user6015054
238
votes
6 answers

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 { Observable } from 'rxjs/Observable'; import {…
Calvin Ferrando
  • 3,794
  • 3
  • 16
  • 26
237
votes
7 answers

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 subscription in an express route handler and the…
Berkeley Martinez
  • 2,786
  • 2
  • 14
  • 18
232
votes
11 answers

'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(() => {}) Observable.from([1,2,3]).subscribe(() => {})
xiaoke
  • 3,272
  • 2
  • 17
  • 20
1
2 3
99 100