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

Angular async pipe and object property

I need to use async pipe without ngFor. I need to check property of object that is async loaded with observable. This is what i want, but not working: Login
Daniel Suchý
  • 1,822
  • 2
  • 14
  • 19
87
votes
9 answers

How to cancel a subscription in Angular2

How does one cancel a subscription in Angular2? RxJS seems to have a dispose method, but I can't figure out how to access it. So I have code that has access to an EventEmitter and subscribes to it, like this: var mySubscription =…
Michael Oryl
  • 20,856
  • 14
  • 77
  • 117
87
votes
4 answers

RxJS - observable doesn't complete when an error occurs

When I create an observable from scratch, and have the observer error, then complete, the done part of the subscription never is invoked. var observer = Rx.Observable.create(function(observer){ observer.onError(new Error('no!')); …
Oved D
  • 7,132
  • 10
  • 47
  • 69
87
votes
1 answer

Node.js Streams vs. Observables

After learning about Observables, I find them quite similar to Node.js streams. Both have a mechanism of notifying the consumer whenever new data arrives, an error occurs or there is no more data (EOF). I would love to learn about the…
urish
  • 8,943
  • 8
  • 54
  • 75
87
votes
6 answers

RxJS: How to not subscribe to initial value and/or undefined?

Being new to RxJS I often create a subject which holds values in the future, but is initially undefined. It can only be undefined the first time. I currently use a filter to skip undefined values, but this is quite cumbersome as I do it everywhere…
Pipo
  • 5,623
  • 7
  • 36
  • 46
85
votes
2 answers

Chaining Observables in RxJS

I'm learning RxJS and Angular 2. Let's say I have a promise chain with multiple async function calls which depend on the previous one's result which looks like: var promiseChain = new Promise((resolve, reject) => { setTimeout(() => { …
Harindaka
  • 4,658
  • 8
  • 43
  • 62
83
votes
3 answers

Rxjs toPromise() deprecated

I have read that toPromise() is being deprecated in RxJS 7 and will be removed in RxJS 8. I have often used it with async await syntax in angular to handle http calls. Is it considered an anti pattern? I understand the concept of streams but an http…
Matias
  • 1,070
  • 2
  • 6
  • 14
82
votes
7 answers

Angular2: convert array to Observable

I have a component that gets the data from a service via http, the problem is that I don't want to hit the API backend every time I show this component. I want my service to check if the data is in memory, if it is, return an observable with the…
Mathius17
  • 2,412
  • 2
  • 21
  • 33
80
votes
7 answers

Is it good to call subscribe inside subscribe?

I need to pass three data to one function from three different APIs: this.service.service1().subscribe( res1 => { this.service.service1().subscribe( res2 => { this.service.service1().subscribe( res3 => { this.funcA(res1, res2, res3); …
Yashwanth Gurrapu
  • 1,039
  • 1
  • 9
  • 14
80
votes
9 answers

RxJS: takeUntil() Angular component's ngOnDestroy()

tl;dr: Basically I want to marry Angular's ngOnDestroy with the Rxjs takeUntil() operator. -- is that possible? I have an Angular component that opens several Rxjs subscriptions. These need to be closed when the component is destroyed. A simple…
marius
  • 1,533
  • 3
  • 16
  • 22
77
votes
3 answers

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

import { Headers, Http } from '@angular/http'; @Injectable() export class PublisherService{ private publishersUrl = 'app/publisher'; constructor(private http: Http) { } getPublishers(): Promise{ return…
Abhishek Sharma
  • 1,420
  • 1
  • 20
  • 30
76
votes
17 answers

Cannot find module 'rxjs-compat/Observable'

I am currently upgrading angular 4 to angular 6 code. I have installed "rxjs": "^6.3.2" and un-installed rxjs-compact as I have migrated the code to use the new rxjs operators. I am still getting the following errors. Dont know the reason why ERROR…
Tom
  • 8,175
  • 41
  • 136
  • 267
75
votes
4 answers

What does $ sign at the end of function name indicate?

Here is the code I'm reviewing... import { Observable } from 'rxjs/Rx'; // reducer import { playerRegister, PlayerState } from './player'; export function getPlayer$ (state$: Observable): Observable { return…
ishandutta2007
  • 16,676
  • 16
  • 93
  • 129
75
votes
8 answers

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

Hi I am using Angular 2 final with router 3.0. I want to filter the events that are emitted from this.router.events What I want to do : import 'rxjs/operator/filter'; //... this.router.events .filter((event:Event) => event instanceof…
ritz078
  • 2,193
  • 3
  • 22
  • 24
73
votes
1 answer

what is a `Scheduler` in RxJS

I'v seen the term Scheduler very frequently in the documentation. But, what does this term mean? I even don't know how to use a so called Scheduler. The official documentation didn't tell me what a Scheduler exactly is. Is this just a common…
yaquawa
  • 6,690
  • 8
  • 35
  • 48