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
37
votes
3 answers

Angular2 Observable and Promise

I started using Angular2 Observable, but I can't find something similar to .then that I used with Promises. This is what I want to accomplish. code from header.component.ts public login() { this._user =…
Ned
  • 3,961
  • 8
  • 31
  • 49
36
votes
3 answers

Angular RxJS Observable: takeUntil vs. unsubscribe with a Subscription

There are several ways to unsubscribe from observables on Angular components (by using ngOnDestroy). Which option below should be preferred and why (e.g. technical reasons, performance, etc.)? Option 1: takeUntil Using RxJS takeUntil to…
Horace P. Greeley
  • 882
  • 1
  • 10
  • 18
36
votes
4 answers

Using Observable in Android

I want to implement a Navigation View with many fragments that depend totally on a value defined in the MainActivity. I know that variables in MainActivity can be accessed using method defined in MainActivity from other Fragments to get the value,…
Kaushik NP
  • 6,733
  • 9
  • 31
  • 60
36
votes
2 answers

What is the difference between Schedulers.io() and Schedulers.computation()

I use Observables in couchbase. What is the difference between Schedulers.io() and Schedulers.computation()?
Osama Abdulsattar
  • 576
  • 1
  • 4
  • 11
35
votes
3 answers

What is the difference between throttleTime vs debounceTime in RxJS and when to choose which?

I'm trying to understand throttleTime vs debounceTime and which one is to be used when? I have an upvote button that makes an API request to the backend (which counts the votes). User can submit button multiple times, but I'd like to limit the times…
Cleave Kokle
  • 373
  • 1
  • 3
  • 5
35
votes
2 answers

This property fromEvent does not exist on type 'typeof Observable' Angular 6

I am having a problem trying to create to turn the keyup events into an observable stream. I am following the Ng-book version 6. I am stuck in an example that makes a search YouTube video as you type. When the search returns we’ll show a list of…
ValRob
  • 2,584
  • 7
  • 32
  • 40
34
votes
2 answers

Using an Observable to detect a change in a variable

I think I misunderstand how Observables are supposed to be used. I want to put a value in, and when the value changes it should emit the new value. I thought that was what they were for, but all the tutorials and docs don't seem to do this, but at…
Jus10
  • 14,519
  • 21
  • 52
  • 77
34
votes
5 answers

How to convert rxJava2's Observable to Completable?

I have Observable stream, and I want to convert it to Completable, how I could do that?
Stepango
  • 4,721
  • 3
  • 31
  • 44
34
votes
3 answers

Angular 2 - Return data directly from an Observable

I've been banging my head against this one trying to figure it out, and no amount of documentation I've been able to read has given me an answer to my question. I have a service which is speaking directly to an API and returning an observable event…
Sidriel
  • 1,160
  • 2
  • 9
  • 16
33
votes
6 answers

Testing Observables with jest

How can I test Observables with Jest? I have an Observable that fires ~every second, and I want to test that the 1st event is correctly fired, before jest times out. const myObservable = timer(0, 1000); // Example here it('should fire', () => { …
jeanpaul62
  • 9,451
  • 13
  • 54
  • 94
33
votes
2 answers

Difference between new Observable(...) and Rx.Observable.create(...)?

I'm updating our software substituting all promises (and other hairy junk) for observables. To make sure that I'm following best practices, I made a quick googlearch and noticed that in some cases, the suggested syntax is by instance whereas in…
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
33
votes
2 answers

Observables: Complete vs finally vs done

When speaking about Observables (especially rxjs), what is the difference between "finally" and "done" or "complete"?
Alexander Taylor
  • 16,574
  • 14
  • 62
  • 83
33
votes
5 answers

Observable.forkJoin() doesn't execute

I have the following code: //Loop: For each user ID/Role ID, get the data userMeta.forEach((businessRole) => { Observable.forkJoin( af.database.object('/roles/'+businessRole.$value), af.database.object('/users/'+businessRole.$key) …
TheUnreal
  • 23,434
  • 46
  • 157
  • 277
33
votes
2 answers

Angular2 Observable - Await multiple function calls before proceeding

I am trying to improve my knowledge of Angular2 by migrating an application currently written in Angular1/AngularJS. One feature in particular has me stumped. I am trying to replicate a feature where a calling function waits to proceed until the…
Benjamin McFerren
  • 822
  • 5
  • 21
  • 36
31
votes
4 answers

How to handle boolean observables with the async pipe in Angular

I have the following code: public obs$: Observable
{{ (obs$ | async) ? 'yes' : 'no' }}
It works as intended, but the if looks a little verbose. The problem is that…
Andreas Gassmann
  • 6,334
  • 7
  • 32
  • 45