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

Observables : Cancel previous http request on new subscription call

I am working on a search functionality for my project. Once the user types anything on the search bar; on any change in search text I'll be sending the text to backend for validation and receive a response (error or no error in…
D_S_X
  • 1,351
  • 5
  • 17
  • 35
31
votes
2 answers

How to create an RXjs RetryWhen with delay and limit on tries

I am trying to make an API call (using angular4), which retries when it fails, using retryWhen. I want it to delay for 500 ms and retry again. This can be achieved with this code: loadSomething(): Observable { return…
Tomer Almog
  • 3,604
  • 3
  • 30
  • 36
31
votes
6 answers

Rxjs number of observable subscriptions

In my Angular 2 app i have many observables and subscriptions. Ofcourse I should unsubscribe when I leave the page, but i'm trying to find out if it's possible to get the number of active subscriptions. Just for debugging info or when i forget to…
Stefan Koenen
  • 2,289
  • 2
  • 20
  • 32
30
votes
9 answers

How to unit test unsubscribe function in angular

I would like to find a way to test unsubscribe function calls on Subscriptions and Subjects. I came up with a few possible solutions, but every one of these have pros and cons. Please keep in mind that I do not want to alter the access modifier of a…
gr4viton
  • 1,434
  • 1
  • 8
  • 21
30
votes
1 answer

Angular - Make multiple HTTP calls sequentially

I need to make a function to make HTTP calls sequentially inorder to use response of one call into other one like getting IP address of user from first call and use that IP to register user in second call. Demo code: registerUser(user: User) { …
Abdul Rafay
  • 3,241
  • 4
  • 25
  • 50
30
votes
3 answers

Http post and get request in angular 6

In angular 5.2.x for http get and post I had this code: post(url: string, model: any): Observable { return this.http.post(url, model) .map(response => response) .do(data => console.log(url + ': ' + JSON.stringify(data))) .catch(err…
unos baghaii
  • 2,539
  • 4
  • 25
  • 42
30
votes
4 answers

How to wait for a http request to finish in Angular?

I've been building a SPA with Angular 4 on the front end and ASP.NET Core 2 on the Backend. Basically, I'm trying to automatically renew an user login, given a valid token. When I reload a page, for example, I would like that Angular stayed logged…
Lucas Arruda
  • 533
  • 1
  • 8
  • 15
30
votes
4 answers

Property 'subscribe' does not exist on type '() => Observable'

service file import { Observable } from 'rxjs/Rx'; import { Http,Response} from '@angular/http'; import { Injectable } from '@angular/core'; import 'rxjs/add/operator/Map'; @Injectable() export class VideoService { private geturl =…
HASSAN MEHMOOD
  • 343
  • 2
  • 5
  • 11
30
votes
6 answers

Filter all 'null' values from an Observable

I have a service with a subject: @Injectable() export class UserService() { private currentUserSubject = new BehaviorSubject(null); public currentUser = this.currentUserSubject.asObservable().distinctUntilChanged(); ... //…
fasth
  • 2,232
  • 6
  • 26
  • 37
30
votes
3 answers

What's the observable equivalent to `Promise.reject`

I had this code return this.http.get(this.pushUrl) .toPromise() .then(response => response.json().data as PushResult[]) .catch(this.handleError); I wanted to use observable instead of Promise how can i return the error…
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
30
votes
4 answers

Get route query params

I am trying to migrate from rc1 to rc4 and i have trouble getting query string parameters. ActivatedRoute object always empty. hero.component.ts import {Component, OnInit} from "@angular/core"; import {Control} from "@angular/common"; import…
izupet
  • 1,529
  • 5
  • 20
  • 42
30
votes
5 answers

RxJs Array of Observable to Observable of Array

For a Web-Application written with Angular2 in TypeScript, I need to work with RxJs Observables. As I never used rxjs before and I am new to reactiveprogramming in general, I sometimes have some difficulties finding the right way to do some specific…
Robert P
  • 9,398
  • 10
  • 58
  • 100
30
votes
2 answers

rxjava add items after observable was created

I just started using rxjava and I got stuck. Maybe I'm not using rxjava in the right way, but I need to add items to an Observable after it was created. So I understand that You can just call Observable.just("Some", "Items") and the subscribers will…
Jelly
  • 4,522
  • 6
  • 26
  • 42
30
votes
3 answers

KnockoutJS - Observable Array of Observable objects

I would like to display an editable list of items, each item of which is editable (kind of like an editable grid, in a way). I am using KnockoutJS. I cannot use just a simple Observable Array because, as the documentation states "An observableArray…
Andy Thomas
  • 1,367
  • 2
  • 14
  • 30
29
votes
3 answers

Passing An ObservedObject To Nested Child Views SwiftUI (SwiftUI Data Flow)

I'm trying to understand why passing an @ObservedObject variable does not work for nested child views. The data is able to be passed but the changes only reflects at the root view where the @ObservedObject variable was created. The changes don't…
Richard Witherspoon
  • 4,082
  • 3
  • 17
  • 33