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
147
votes
4 answers

Property 'catch' does not exist on type 'Observable'

On the Angular 2 documentation page for using the Http service, there is an example. getHeroes (): Observable { return this.http.get(this.url) .map(this.extractData) .catch(this.handleError); } I…
BrianRT
  • 1,952
  • 5
  • 18
  • 27
139
votes
8 answers

Angular 4+ ngOnDestroy() in service - destroy observable

In an angular application we have ngOnDestroy() lifecycle hook for a component / directive and we use this hook to unsubscribe the observables. I want to clear / destory observable that are created in an @injectable() service. I saw some posts…
mperle
  • 3,342
  • 8
  • 20
  • 34
137
votes
4 answers

How to throw error from RxJS map operator (angular)

I want to throw an error from my observable's map operator based on a condition. For instance if correct API data is not received. Please see the following code: private userAuthenticate( email: string, password: string ) { return…
Hassan
  • 2,308
  • 5
  • 21
  • 31
135
votes
5 answers

Can I use RxJS vs Redux/context when trying to manage and access state in different components and handler methods

I know Redux is a better "implementation" of Flux, or better saying it's a redesign to simplify things (application state management). I have heard a lot about reactive programming (RxJS), but I haven't dived to learn it yet. So my question is: are…
Oswaldo
  • 3,296
  • 4
  • 25
  • 35
134
votes
4 answers

Rxjs: Observable.combineLatest vs Observable.forkJoin

I'm wondering what are the differences between Observable.combineLatest and Observable.forkJoin? As far as I can see, the only difference is forkJoin expects the Observables to be completed, while combineLatest returns the latest values.
Tuong Le
  • 18,533
  • 11
  • 50
  • 44
134
votes
4 answers

When to use asObservable() in rxjs?

I am wondering what is the use of asObservable: As per docs: An observable sequence that hides the identity of the source sequence. But why would you need to hide the sequence?
born2net
  • 24,129
  • 22
  • 65
  • 104
134
votes
8 answers

What is "callback hell" and how and why does RX solve it?

Can someone give a clear definition together with a simple example that explains what is a "callback hell" for someone who does not know JavaScript and node.js ? When (in what kind of settings) does the "callback hell problem" occur? Why does it…
jhegedus
  • 20,244
  • 16
  • 99
  • 167
131
votes
11 answers

How to make one Observable sequence wait for another to complete before emitting?

Say I have an Observable, like so: var one = someObservable.take(1); one.subscribe(function(){ /* do something */ }); Then, I have a second Observable: var two = someOtherObservable.take(1); Now, I want to subscribe() to two, but I want to make…
Stephen
  • 18,827
  • 9
  • 60
  • 98
125
votes
8 answers

How to 'wait' for two observables in RxJS

In my app i have something like: this._personService.getName(id) .concat(this._documentService.getDocument()) .subscribe((response) => { console.log(response) this.showForm() }); //Output: …
gog
  • 11,788
  • 23
  • 67
  • 129
121
votes
8 answers

flatMap, mergeMap, switchMap and concatMap in rxjs?

Someone, please explain the difference between SwitchMap and FlatMap in terms of Javascript ( in angular perspective, rxjs 5) In my understanding. SwitchMap only emits the latest observable value and cancels the previous observable. flatMap collects…
xkeshav
  • 53,360
  • 44
  • 177
  • 245
121
votes
4 answers

Using an array from Observable Object with ngFor and Async Pipe Angular 2

I am trying to understand how to use Observables in Angular 2. I have this service: import {Injectable, EventEmitter, ViewChild} from '@angular/core'; import {Observable} from "rxjs/Observable"; import {Subject} from "rxjs/Subject"; import…
C. Kearns
  • 1,531
  • 3
  • 13
  • 18
119
votes
13 answers

Angular 4 Interceptor retry requests after token refresh

Hi I am trying to figure out how implement the new angular interceptors and handle 401 unauthorized errors by refreshing the token and retrying the request. This is the guide I have been following:…
Kovaci
  • 1,211
  • 2
  • 9
  • 8
117
votes
2 answers

Difference between .unsubscribe to .take(1)

I wonder, if there is any difference in performance between using .take(1) and .unsubscribe when unsubscribe is used right after the subscription: var observable = Rx.Observable.interval(100); First: var subscription =…
TheUnreal
  • 23,434
  • 46
  • 157
  • 277
117
votes
4 answers

Promise.all behavior with RxJS Observables?

In Angular 1.x I would sometimes need to make multiple http requests and do something with all the responses. I would throw all the promises in an array and call Promise.all(promises).then(function (results) {...}). Angular 2 best practices seem to…
Corey Ogburn
  • 24,072
  • 31
  • 113
  • 188
113
votes
2 answers

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

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,…
Amadou Beye
  • 2,538
  • 3
  • 16
  • 37