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
108
votes
11 answers

Why do we need to use flatMap?

I am starting to use RxJS and I don't understand why in this example we need to use a function like flatMap or concatAll; where is the array of arrays here? var requestStream = Rx.Observable.just('https://api.github.com/users'); var…
user233232
  • 6,067
  • 9
  • 29
  • 37
106
votes
10 answers

How to throw an observable error manually?

I am working on an Angular app in which I am making a rest call through HTTP as below: login(email, password) { let headers = new Headers(); headers.append('Content-Type', 'application/x-www-form-urlencoded'); let options = new…
Bhushan Gadekar
  • 13,485
  • 21
  • 82
  • 131
104
votes
22 answers

TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable

I am trying to map from a service call but getting an error. Looked at subscribe is not defined in angular 2? and it said that in order to subscribe we need to return from inside the operators. I have return statements as well. Here's my…
Aakash Thakur
  • 3,837
  • 10
  • 33
  • 64
103
votes
6 answers

combineLatest deprecated in favor of static combineLatest

After running the rxjs migration tool using rxjs-5-to-6-migrate -p src/tsconfig.app.json I'm now getting a linting error: combineLatest is deprecated: Deprecated in favor of static combineLatest. Here is my code before running the migration…
Samer
  • 3,848
  • 4
  • 25
  • 24
103
votes
2 answers

Chaining RxJS Observables from http data in Angular2 with TypeScript

I'm currently trying to teach myself Angular2 and TypeScript after happily working with AngularJS 1.* for the last 4 years! I have to admit I am hating it but I am sure my eureka moment is just around the corner... anyway, I have written a service…
Mike Sav
  • 14,805
  • 31
  • 98
  • 143
99
votes
2 answers

fromPromise does not exist on type Observable

In Angular 2 using rxjs I was trying to convert a Promise to Observable. As many of online guides showed I used fromPromise on Observable. Which throws error: Property 'fromPromise' does not exist on type 'typeof Observable'. Observable was…
Ahmad
  • 2,629
  • 3
  • 22
  • 27
96
votes
6 answers

Get current value from Observable without subscribing (just want value one time)

How can I get the current value from an Observable without subscribing to it? I just want the current value one time and not new values as they are coming in.
EricC
  • 5,720
  • 13
  • 52
  • 71
96
votes
8 answers

RxJS sequence equivalent to promise.then()?

I used to develop a lot with promise and now I am moving to RxJS. The doc of RxJS doesn't provide a very clear example on how to move from promise chain to observer sequence. For example, I usually write promise chain with multiple steps, like // a…
Haoliang Yu
  • 2,987
  • 7
  • 22
  • 28
93
votes
6 answers

How to return observable from subscribe

I'm trying to return an observable when I get a certain value in a subscriber, but I fail miserably. This is the code: canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):Observable { // get route to be activated …
Dragos Ionescu
  • 1,163
  • 1
  • 9
  • 12
93
votes
4 answers

Child listens for parent event in Angular 2

In angular docs there is a topic about listening for child events from parents. That's fine. But my purpose is something reverse!. In my app there is an 'admin.component' that holds the layout view of admin page (sidebar menu,task bar, status…
Hamed Hamedi
  • 1,461
  • 1
  • 10
  • 19
91
votes
19 answers

rxjs/Subject.d.ts error : Class 'Subject' incorrectly extends base class 'Observable'

I extracted sample template code from this tutorial and did below two steps to get started - npm install // worked fine and created node_modules folder with all dependencies npm start // failed with below…
Deepak S
  • 1,544
  • 3
  • 15
  • 33
91
votes
4 answers

RXJS Wait for all observables in an array to complete (or error)

I'm pushing observables into an array like such... var tasks$ = []; tasks$.push(Observable.timer(1000)); tasks$.push(Observable.timer(3000)); tasks$.push(Observable.timer(10000)); I want an Observable that emits when all tasks$ have completed. …
josh-sachs
  • 1,749
  • 2
  • 15
  • 19
90
votes
3 answers

Best way to import Observable from rxjs

In my angular 2 app I have a service that uses the Observable class from the rxjs library. import { Observable } from 'rxjs'; At the moment I am just using Observable so that I can use the toPromise() function. I read in another StackOverflow…
Danoram
  • 8,132
  • 12
  • 51
  • 71
89
votes
3 answers

How to get data from observable in angular2

I am trying to print the result of http call in Angular using rxjs Consider the following code import { Component, Injectable, OnInit } from '@angular/core'; import { Http, HTTP_PROVIDERS } from '@angular/http'; import…
testing
  • 2,303
  • 4
  • 20
  • 32
88
votes
5 answers

Behaviour subject initial value null?

private customer: Subject = new BehaviorSubject(null); setCustomer(id, accountClassCode) { this.customer.next({'id': id, 'accountClassCode': accountClassCode}); } getCustomer() { return this.customer.asObservable(); } I'm…
None
  • 8,817
  • 26
  • 96
  • 171