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
29
votes
2 answers

What is the point of using SubSink instead of a Subscriptions array

I just watched a ngConf video of John Papa talking about SubSink as a best practice in order to unsubscribe from obversables. I was actually using Subscriptions[] then push subscriptions into it then forEach unsubscribe at cmp destroy. Is their…
The Segfault
  • 939
  • 1
  • 10
  • 23
29
votes
3 answers

Angular 6 add items into Observable

I'm new to Angular 6 and i'm having trouble on how i can add objects into observable in a service. i have this observable getContacts(){ return this.contact = this.http.get('https://jsonplaceholder.typicode.com/users'); } and i need to add…
Francis Rubia
  • 439
  • 2
  • 6
  • 14
29
votes
3 answers

Why Angular uses Observable for HttpClient?

As per https://angular.io/tutorial/toh-pt6 In general, an observable can return multiple values over time. An observable from HttpClient always emits a single value and then completes, never to emit again. Which is indeed true, Http…
Namit
  • 301
  • 3
  • 6
29
votes
1 answer

Merging http observables using forkjoin

I'm trying to avoid nested observables by using forkjoin. The current (nested) version looks like this: this.http.get('https://testdb1.firebaseio.com/.json').map(res => res.json()).subscribe(data_changes => { …
Martin
  • 1,060
  • 2
  • 16
  • 28
29
votes
2 answers

What does the .subscribe() function do?

I am coding an API with Angular2 and NodeJS, I am implementing services for my ِAPI that is supposed to get a list of tasks and display it. Here is the task service: import {Injectable} from '@angular/core'; import {Http, Headers} from…
Jaro
  • 1,587
  • 5
  • 20
  • 39
29
votes
1 answer

angular2 wait until observable finishes in if condition

I have implemented a if statement like this if (this.service.check() ) { return true; } else { } this if condition waits for a response from the backend. But before the observable gets executed it's going into the else statement and…
Kokulan
  • 1,316
  • 3
  • 19
  • 35
29
votes
3 answers

Property '_body' does not exist on type 'Response'

I am using Angular 2 and getting this error when using an observable Property '_body' does not exist on type 'Response'. The code is below this.securitiesService.getMarketMovers() .subscribe(data => { …
georgej
  • 3,041
  • 6
  • 24
  • 46
28
votes
4 answers

Is an EventListener an Observable?

I am currently following a class about Design Patterns and was wondering whether an EventListener is an Observable? I don't really see a difference between them because both have a list of subscribers and notify these subscribers when something…
Daan
  • 432
  • 1
  • 7
  • 17
28
votes
1 answer

Is RxJS.Observable a monad?

Is Observable really a monad? Does it abide by Monad laws (https://wiki.haskell.org/Monad_laws)? Doesn't seem to me like it does. But maybe my understanding is wrong and somebody can shed some light on the issue. My current reasoning is (I'm using…
Mateusz Wit
  • 425
  • 5
  • 10
28
votes
2 answers

Angular 2+ wait for subscribe to finish to update/access variable

I am having an issue with my variables being undefined. I am certain this is because the observable hasn't finished. Here is the part of my code in my .ts file that is causing the issue. (I'm placing the minimum code required to understand the…
cup_of
  • 6,397
  • 9
  • 47
  • 94
28
votes
3 answers

How to create an observable in Angular 2

I am trying to evaluate Angular 2 and I am having problems with observables. I am trying to create a simple service that initially returns a hard coded array but will eventually get the data from a webservice. However, I can't get it to build…
Al_B
  • 407
  • 1
  • 6
  • 10
28
votes
4 answers

Extending Angular 2 ngModel directive to use observables

Angular 2 ngModel directive works with variables and functions like Instead of variables and functions, I would like to use BehaviorSubjects instead
nwarp
  • 731
  • 4
  • 8
  • 17
28
votes
4 answers

How can I complete Observable in RxJS

Let's say we have an Observable: var observable = Rx.Observable .fromEvent(document.getElementById('emitter'), 'click'); How can I make it Complete (what will trigger onComplete event for all subscribed Observers) ?
ulfryk
  • 683
  • 1
  • 6
  • 15
27
votes
4 answers

angular2: How to use observables to debounce window:resize

so i am trying to figure out a way to debouce window:resize events using observables, so some kind of function would be called only after user stoped resizing window or some time has passed without size change (say…
LithStud
  • 464
  • 2
  • 6
  • 16
27
votes
2 answers

Knockout.JS: Triggers based on changes in an observable

I have an input element which is bound to a knockout observable: This updates the observable on each keyup. I now want to trigger additional events when the value changes. The…
gzost
  • 2,375
  • 1
  • 18
  • 25