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
72
votes
5 answers

Simple filter on array of RXJS Observable

I am starting my project with Angular2 and the developers seem to recommend RXJS Observable instead of Promises. I have achieved to retrieve a list of elements (epics) from the server. But how can I filter the elments by using for example an id? The…
Johannes
  • 2,732
  • 5
  • 23
  • 32
72
votes
4 answers

Hot and Cold observables: are there 'hot' and 'cold' operators?

I reviewed the following SO question: What are the Hot and Cold observables? To summarize: a cold observable emits its values when it has an observer to consume them, i.e. the sequence of values received by observers is independent of time of…
user3743222
  • 18,345
  • 5
  • 69
  • 75
71
votes
4 answers

How to convert an Observable into a BehaviorSubject?

I'm trying to convert an Observable into a BehaviorSubject. Like this: a$ = new Observable() b$ = BehaviorSubject.create(new BehaviorSubject(123), a$) // I have also tried: a$ = new Observable() b$ = new BehaviorSubject(a$, 123) // And: a$ = new…
awmleer
  • 1,658
  • 3
  • 13
  • 28
71
votes
11 answers

How to cancel/unsubscribe all pending HTTP requests in Angular 4+

How to cancel/abort all pending HTTP requests in angular 4+. There is an unsubscribe method to cancel HTTP Requests but how to cancel all pending requests all at once. Especially while route change. There is one thing I did ngOnDestroy() { …
Sibiraj
  • 4,486
  • 7
  • 33
  • 57
70
votes
2 answers

Rxjs One Observable Feeding into Another

I have a rather clunky looking set of code where the data from one observable is feed into another, like such: let source = this.myService.getFoo() .subscribe(result => { let source2 = this.myService.getMoo(result) …
Siegmund Nagel
  • 1,321
  • 2
  • 11
  • 19
68
votes
5 answers

How to pass observable value to @Input() Angular 4

I am new to angular and I have the following situation which is I have a service getAnswers():Observable[]>and two components that are related to each other. online-quote dynamic-form online-quote component calls the service…
AlejoDev
  • 4,345
  • 9
  • 36
  • 67
68
votes
2 answers

Simple way to get the current value of a BehaviorSubject with rxjs5

Previously in rxjs4 there was a method in the BehaviorSubject called: getValue() (doc here). This method does not exist anymore in rxjs5. So the only solution that I found to get the value of a BehaviorSubject was: let…
Clement
  • 3,860
  • 4
  • 24
  • 36
68
votes
2 answers

ObjectUnsubscribedError when trying to prevent subscribing twice

I have a Service and a component that uses it: PagesService PagesListComponent In the PagesService I have an array of Pages. I notify changes in the array via a BehaviorSubject which both of them are subscribed to. The PagesService are provided at…
AlvYuste
  • 915
  • 1
  • 6
  • 14
67
votes
5 answers

why should we use subscribe() over map() in Angular?

I am trying to take advantage of observables in angular2 and got confused on why should i use map() over subscribe(). Suppose i am getting values from a webApi, like this this.http.get('http://172.17.40.41:8089/api/Master/GetAllCountry') Now…
Lijin Durairaj
  • 3,341
  • 11
  • 31
  • 50
67
votes
5 answers

How to catch error and continue executing a sequence in RxJs?

I have a list of items to parse, but the parsing of one of them can fail. What is the "Rx-Way" to catch error but continue executing the sequence Code Sample: var observable = Rx.Observable.from([0,1,2,3,4,5]) .map( function(value){ …
Cheborra
  • 2,627
  • 4
  • 23
  • 39
66
votes
6 answers

How to correctly return a void Observable?

In my Angular 4 application, I have a method that have to return an Observable. This method has 3 conditions. First and second conditions make a get call, but the third condition does nothing and in this case I have to return an Observable as well,…
Alessandro Celeghin
  • 4,039
  • 14
  • 49
  • 95
66
votes
4 answers

How do I make an Observable Interval start immediately without a delay?

I want my observable to fire immediately, and again every second. interval will not fire immediately. I found this question which suggested using startWith, which DOES fire immediately, but I then get a duplicate first…
adamdport
  • 11,687
  • 14
  • 69
  • 91
65
votes
6 answers

rxjs flatmap missing

I try to chain multiple rx.js observables and pass the data. Flatmap should be the fitting operator but with an import of import { Observable } from 'rxjs/Observable'; it is not found: Error TS2339: Property 'flatmap' does not exist on type…
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292
64
votes
6 answers

Angular 2 Observable with multiple subscribers

I have an angular 2 service that fetch data from an API this service has 3 subscribers (defined in Components) each doing something else with the data (different graphs) I'm noticing that I'm doing three GET requests to the API while what i want to…
naoru
  • 2,149
  • 5
  • 34
  • 58
63
votes
1 answer

RxJs pipe and lettable operator `map`: 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>'

I have this very basic example that uses lettable operator map with pipe from rxjs@5.5: import { map } from 'rxjs/operator/map'; let o = of(1, 2, 3, 4).pipe( map((v) => v * 2) ); But it produces the error Error:(34, 5) TS2684:The 'this'…
Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488