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
218
votes
18 answers

Observable.of is not a function

I am having issue with importing Observable.of function in my project. My Intellij sees everything. In my code I have: import {Observable} from 'rxjs/Observable'; and in my code I use it like that: return Observable.of(res); Any ideas?
uksz
  • 18,239
  • 30
  • 94
  • 161
202
votes
16 answers

Angular 2 beta.17: Property 'map' does not exist on type 'Observable'

I just upgraded from Angular 2 beta16 to beta17, which in turn requires rxjs 5.0.0-beta.6. (Changelog here: https://github.com/angular/angular/blob/master/CHANGELOG.md#200-beta17-2016-04-28) In beta16 all was working well regarding Observable/map…
brando
  • 8,215
  • 8
  • 40
  • 59
196
votes
7 answers

How can I `await` on an Rx Observable?

I'd like to be able to await on an observable, e.g. const source = Rx.Observable.create(/* ... */) //... await source; A naive attempt results in the await resolving immediately and not blocking execution Edit: The pseudocode for my full intended…
CheapSteaks
  • 4,821
  • 3
  • 31
  • 48
187
votes
5 answers

What is pipe() function in Angular

Pipes are filters for transforming data (formats) in the template. I came across the pipe() function as below. What does this pipe() function exactly mean in this case? return this.http.get(url) .pipe( tap(_ => this.log(`fetched hero…
Dinesh Sharma
  • 2,117
  • 3
  • 13
  • 9
184
votes
16 answers

Angular - "has no exported member 'Observable'"

Typescript code: import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { of } from 'rxjs/observable/of'; import { Hero } from './hero'; import { HEROES } from './mock-heroes'; @Injectable({ providedIn:…
Thomas Lee
  • 2,757
  • 2
  • 11
  • 13
182
votes
17 answers

node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected error after installation of Angular 6

I got an error of node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected. after the installation of Angular 6. Check the error: ERROR in node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';'…
SSP
  • 1,937
  • 2
  • 8
  • 7
180
votes
5 answers

What is pipe for in RxJS?

I think I have the base concept, but there are some obscurities So in general this is how I use an Observable: observable.subscribe(x => { }) If I want to filter data I can use this: import { first, last, map, reduce, find, skipWhile } from…
enno.void
  • 6,242
  • 4
  • 25
  • 42
179
votes
3 answers

Angular2 http.get() ,map(), subscribe() and observable pattern - basic understanding

Now, I have an initial page where I have three links. Once you click on the last 'friends' link, appropriate friends Component gets initiated. In there, I want to fetch/get list of my friends strored into friends.json file. Till now everything works…
nyks
  • 2,103
  • 6
  • 14
  • 17
177
votes
11 answers

Upgrading to Angular 10 - Fix CommonJS or AMD dependencies can cause optimization bailouts

I am trying to upgrade my Angular 9 app to Angular 10 version, but I am getting the below warning after the upgrade rxjs\BehaviorSubject.js depends on rxjs-compat/BehaviorSubject How can I fix this?
Ora
  • 1,889
  • 2
  • 9
  • 9
177
votes
3 answers

Observable Finally on Subscribe

According to this artcle, onComplete and onError function of the subscribe are mutually exclusive. Meaning either onError or onComplete events will fire up in my subscribe. I have a logic block which needs to be executed whether I receive an…
Amir Tugi
  • 2,386
  • 3
  • 16
  • 18
170
votes
3 answers

RxJS: How would I "manually" update an Observable?

I think I must be misunderstanding something fundamental, because in my mind this should be the most basic case for an observable, but for the life of my I can't figure out how to do it from the docs. Basically, I want to be able to do this: //…
LiamD
  • 1,958
  • 2
  • 13
  • 13
169
votes
26 answers

How can I close a dropdown on click outside?

I would like to close my login menu dropdown when the user click anywhere outside of that dropdown, and I'd like to do that with Angular2 and with the Angular2 "approach"... I have implemented a solution, but I really do not feel confident with it.…
Clement
  • 3,860
  • 4
  • 24
  • 36
169
votes
6 answers

How to create an Observable from static data similar to http one in Angular?

I am having a service that has this method: export class TestModelService { public testModel: TestModel; constructor( @Inject(Http) public http: Http) { } public fetchModel(uuid: string = undefined): Observable { …
Michail Michailidis
  • 11,792
  • 6
  • 63
  • 106
152
votes
12 answers

How to return value from function which has Observable subscription inside?

I dont know how to extract value from Observable to be returned by function in which Observable is present. I need just a value from it to be returned, nothing else. Current version which works function getValueFromObservable() { …
Teddy
  • 2,277
  • 3
  • 15
  • 19
151
votes
10 answers

What is the difference between Observable and a Subject in rxjs?

I was going through this blog and reading about Observables and couldn't figure out the difference between the Observable and a Subject.
Lijin Durairaj
  • 4,910
  • 15
  • 52
  • 85