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
80
votes
7 answers

Is it good to call subscribe inside subscribe?

I need to pass three data to one function from three different APIs: this.service.service1().subscribe( res1 => { this.service.service1().subscribe( res2 => { this.service.service1().subscribe( res3 => { this.funcA(res1, res2, res3); …
Yashwanth Gurrapu
  • 1,039
  • 1
  • 9
  • 14
79
votes
7 answers

LiveData update on object field change

I'm using Android MVVM architecture with LiveData. I have an object like this public class User { private String firstName; private String lastName; public String getFirstName() { return firstName; } public void…
Alireza Ahmadi
  • 5,122
  • 7
  • 40
  • 67
79
votes
6 answers

Unit testing an observable in Angular 2

What is the correct way of unit testing a service returning an Observable result in Angular 2? Let's say we have a getCars method in a CarService service class: ... export class CarService{ ... getCars():Observable{ return…
Erdinc Guzel
  • 937
  • 1
  • 6
  • 10
75
votes
6 answers

Wait for Angular 2 to load/resolve model before rendering view/template

In Angular 1.x, UI-Router was my primary tool for this. By returning a promise for "resolve" values, the router would simply wait for the promise to complete before rendering directives. Alternately, in Angular 1.x, a null object will not crash a…
shannon
  • 8,664
  • 5
  • 44
  • 74
72
votes
5 answers

Simple filter on array of RXJS Observable

I am starting my project with Angular2 and the developers seem to recommend RXJS Observable instead of Promises. I have achieved to retrieve a list of elements (epics) from the server. But how can I filter the elments by using for example an id? The…
Johannes
  • 2,732
  • 5
  • 23
  • 32
71
votes
4 answers

How to convert an Observable into a BehaviorSubject?

I'm trying to convert an Observable into a BehaviorSubject. Like this: a$ = new Observable() b$ = BehaviorSubject.create(new BehaviorSubject(123), a$) // I have also tried: a$ = new Observable() b$ = new BehaviorSubject(a$, 123) // And: a$ = new…
awmleer
  • 1,658
  • 3
  • 13
  • 28
70
votes
2 answers

Rxjs One Observable Feeding into Another

I have a rather clunky looking set of code where the data from one observable is feed into another, like such: let source = this.myService.getFoo() .subscribe(result => { let source2 = this.myService.getMoo(result) …
Siegmund Nagel
  • 1,321
  • 2
  • 11
  • 19
67
votes
5 answers

why should we use subscribe() over map() in Angular?

I am trying to take advantage of observables in angular2 and got confused on why should i use map() over subscribe(). Suppose i am getting values from a webApi, like this this.http.get('http://172.17.40.41:8089/api/Master/GetAllCountry') Now…
Lijin Durairaj
  • 3,341
  • 11
  • 31
  • 50
66
votes
4 answers

TypeScript Error: Property '0' is missing in type

I have my interface like this export interface Details { Name: [{ First: string; Last: string; }]; } I have an observable config variable: Configuration: KnockoutObservable
= ko.observable
(); and I would like to…
rkt
  • 1,171
  • 2
  • 9
  • 18
65
votes
6 answers

rxjs flatmap missing

I try to chain multiple rx.js observables and pass the data. Flatmap should be the fitting operator but with an import of import { Observable } from 'rxjs/Observable'; it is not found: Error TS2339: Property 'flatmap' does not exist on type…
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292
64
votes
2 answers

Events vs Streams vs Observables vs Async Iterators

Currently, the only stable way to process a series of async results in JavaScript is using the event system. However, three alternatives are being developed: Streams: https://streams.spec.whatwg.org Observables:…
Daniel Herr
  • 19,083
  • 6
  • 44
  • 61
61
votes
1 answer

SwiftUI -> Thread 1: Fatal error: No observable object of type MyObject.Type found (EnvironmentObject in sheet)

I'm building an app with SwiftUI. When I was trying to display a sheet (previously Modal), this error message appears: Thread 1: Fatal error: No observable object of type BixiStationCombinedListViewModel.Type found. A View.environmentObject(_:) for…
Daymo502
  • 825
  • 1
  • 6
  • 10
61
votes
1 answer

Angular 2: why use switchMap when retrieving route params?

I'm reading the Angular Guide about Routing & Navigation. They use this code for retrieving the router's param 'id' and using it to get a hero with the service service: ngOnInit() { this.route.params .switchMap((params: Params) =>…
Andrea
  • 15,900
  • 18
  • 65
  • 84
58
votes
7 answers

Angular 4: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'

i need your help, i'm trying to display some datas from my firebase but it trhows me an error like InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'. There is my service: import { Injectable } from '@angular/core'; import {…
P_Js
  • 593
  • 1
  • 5
  • 7
58
votes
3 answers

Angular Template: How to bind RXJS Observable and read its properties?

I have created this interface: interface IGame { name: string; description: string; } I'm using it as an Observable and passing it as Input to the Component: @Input() public game: Observable; I can see its value printed using the…
Lior Kooznits
  • 623
  • 1
  • 5
  • 6