Questions tagged [observable]

An observable is typically a programming construct that can be "watched" by other parts of the code, called the "observers". Different frameworks and programming languages have different implementations for observables, so this tag should typically be used in conjunction with others.

An observable is typically a programming construct that can be "watched" by other parts of the code, called the "observers". Different frameworks and programming languages have different implementations for observables, so this tag should typically be used in conjunction with others.

An observer may be any object that implements interface Observer. An observable object can have one or more observers. After an observable instance changes, an application calling the Observable's “notification” method causes all of its observers to be notified of the change by a call to their update method.

References

9527 questions
46
votes
2 answers

Use case of Observable .do() operator (rxjs)

 Context : I'm building an angular 2 app (with a Firebase API). I'm using the AngularFire module. I was wondering how I can mix the canActivate method with the AngularFire auth Observable, and I found this post. The answer is to make the canActivate…
soywod
  • 4,377
  • 3
  • 26
  • 47
46
votes
4 answers

Knockoutjs computed passing parameters

I am wondering if it is possible with knockoutjs to pass arguments when binding. I am binding a list of checkboxes and would like to bind to a single computed observable in my viewmodel. In my viewmodel (based on parameter passed to the read…
Qaiser Iftikhar
  • 495
  • 1
  • 4
  • 7
45
votes
5 answers

"rxjs" observable.throw is not a function - Angular4

I've been learning Angular 4 and everything was going smoothly until I tried to implement catch handling in a service. I'm trying to use "rxjs" catch and throw but I've got an undefined function error in my console. import { Injectable } from…
nick gowdy
  • 6,191
  • 25
  • 88
  • 157
45
votes
2 answers

create Observable from result

I am trying Angular2. I noticed that the http service use Observable object instead of Promise (I don't like much that choice.. async/await are arriving). In my service, I download a list of Plants from the webservice. Clicking on a plant I show the…
user3471528
  • 3,013
  • 6
  • 36
  • 60
44
votes
4 answers

RxJS Observables nested subscriptions?

What's the way to simplify something like the following code example? I can't find the right operator.. could anyone give a short example? this.returnsObservable1(...) .subscribe( success => { this.returnsObservable2(...) …
Max Solid
  • 1,213
  • 3
  • 21
  • 32
44
votes
3 answers

TypeScript - wait for an observable/promise to finish, and return observable

I am quite new to TypeScript & RxJS, and I am trying to return an Observable after another Observable is finished: public myObservable = () : Observable => { console.log('retrieving the token in DB'); return…
Geoffrey D
  • 578
  • 1
  • 6
  • 13
43
votes
4 answers

RxJava2 observable take throws UndeliverableException

As I understand RxJava2 values.take(1) creates another Observable that contains only one element from the original Observable. Which MUST NOT throw an exception as it is filtered out by the effect of take(1) as it's happened second. as in the…
abd3lraouf
  • 1,438
  • 1
  • 18
  • 24
43
votes
2 answers

How to get last value from a Subject?

I have two Angular2 components which need to share data via a service: @Injectable() export class SearchService { private searchResultSource = new Subject() searchResult$ = this.searchResultSource.asObservable() …
kdu
  • 1,259
  • 4
  • 12
  • 18
42
votes
5 answers

How to use the MatTableDataSource with an observable?

I am using the mat-table and I am trying to use the MatTableDataSource with an observable (I get the data from a web service), but I don't know how to configure the MatTableDataSource to use an observable instead of an array. Is the only solution to…
42
votes
4 answers

Type 'Observable' is not assignable to type 'Observable'
In my Api service I have this simple getUsers function to fetch all of the users on the api. public getUsers(url: string): Observable { return this._http.get(url); } This is my IUser interface, I have made all the field optional for…
Sam Kelham
  • 1,357
  • 4
  • 15
  • 28
42
votes
2 answers

How to stop an interval on an Observable in RxJS

I have a specific situation where I'm using an RxJS interval, but at any given moment I may need to stop that interval. I assumed there was something easy like a cancel() or stop(). Similar to clearTimeout. This is possible to stop an interval once…
selanac82
  • 2,920
  • 4
  • 27
  • 37
41
votes
5 answers

Angular - Observable with async pipe used multiple times in template... Good Practice or Bad?

If I have the need to bind multiple properties from the same observable within my component template... For example: ... ...am I…
Mark
  • 486
  • 1
  • 4
  • 10
39
votes
4 answers

RxJava introduced Single. How do I convert an Observable to a Single?

RxJava recently introduced Single. Is there a way to convert an already existing Observable (that's pretty much a Single) to a Single without modifying the source of the original observable? For example, I have an api service class with a method…
loeschg
  • 29,961
  • 26
  • 97
  • 150
37
votes
3 answers

Type 'boolean' is not assignable to type 'Observable'

I have that code method(): Observable { return this._http.get('sessionId=' + sessionId).map(res=> { if (res.status === "success") { return true; } return false; }); } But when sessionId is '' it throws an…
gsiradze
  • 4,583
  • 15
  • 64
  • 111
37
votes
5 answers

RXJS Observable - How to call next from outside of the Observable's constructor

I am building a service which exposes an Observable. In this service I receive external function calls which should trigger a next call on the Observable so that various consumers get the subscribe event. During Observer constructor I can call next…
Joshua Ohana
  • 5,613
  • 12
  • 56
  • 112