Questions tagged [rxjs-observables]

759 questions
4
votes
2 answers

Object is of type 'unknown'

I have simple Rxjs function Observables and Operators to return new Observable.in my code i am using filter and map operators chained inside a pipe sadly, i get error TS2571: Object is of type 'unknown'. inside filter operator data The code is…
4
votes
3 answers

Do I need to unsubscribe from an Angular Observable?

It's surprisingly hard to get a straight answer on if and when you should unsubscribe from an Angular Observable. I have the following scenario: this.subscription = this.service.makeHTTPCall(stuff).subscribe(x => { //do something }); There are a…
JKennedy
  • 18,150
  • 17
  • 114
  • 198
4
votes
3 answers

Angular/RXJS, How do I sort an Observable Array of objects based on a SPECIFIC String value?

I have an interesting problem (I think) and would love some help. I am returning an Observable[DisplayCard[]] that is filtered based on a value. That all works great. After I filter that array based on a value, I NOW want to sort the returned array…
Donny groezinger
  • 127
  • 1
  • 3
  • 9
4
votes
2 answers

Order of execution with rxjs asapscheduler

Considering I have the following code: let Rx = window['rxjs']; const { of, queueScheduler, asapScheduler, asyncScheduler, animationFrameScheduler } = Rx; const { observeOn, tap } = Rx.operators; console.clear(); let source$ =…
4
votes
1 answer

Utilizing rxjs repeatWhen in http request pipe in order to repeat the request if desired response is not returned

I'm trying to use below simplified version of my http request pipeline to ensure that if my response does not have the required data in res.myCondition to utlize repeatWhen and make another call, but I'm clearly not utilizing repeatWhen the way…
4
votes
1 answer

Marble testing rxjs observable on an angular service

I have an Angular service with an exposed observable that I'm trying to marble test with the rxjs TestScheduler. A method on the service controls the value the observable emits, using a BehaviorSubject as the source. Here's a really simple…
aasukisuki
  • 1,186
  • 1
  • 11
  • 33
4
votes
2 answers

Do you need to unsubscribe from a subscription to router params in Angular?

When you subscribe to query params in a component, do you need to unsubscribe? I'm trying to avoid a memory leak. Subscription with variable for unsubscribe() subscription$: Subscription constructor(private route: ActivatedRoute) {} …
4
votes
5 answers

How to best handle multiple subscriptions to the same observable on the template?

Let's say I have an observable called 'todoList$'. Using the 'async' operator, I'm able to automatically subscribe/unsubscribe from it. The problem in the code below is that there are two identical subscriptions to the same observable:
Kode_12
  • 4,506
  • 11
  • 47
  • 97
4
votes
2 answers

How to use shareReplay for cache HTTP response with request params

I have a scenario like I need to fetch file content when click on a file. I want to cache the file content API with shareReplay(), how can I achieve it? fileService.getContent is an API service which will fetch content with params(repository_id,…
huan feng
  • 7,307
  • 2
  • 32
  • 56
4
votes
3 answers

RxJs: Can you spread operators as arguments into pipe operator

I have two observable streams which do very separate mapping logic, but then ultimately end with following 3 operators: this.selection .pipe( ..Custom mapping operators tap(_ => this.devicesLoading = true), switchMap(d =>…
MikeByte
  • 111
  • 9
4
votes
3 answers

How to dispatch multiple actions from an effect in ngrx conditionally

I am a back-end developer starting with front-end development for a project I am working on. The front-end uses Angular7 and NgRx. I have studied a lot in the last 4 days, but here is something I am stuck with and would appreciate your help. I…
4
votes
2 answers

Angular 7 Wait for http network call to finish before triggering next one

I have a data service that triggers http calls periodically and when required by other services. Now, this services work asynchronously so it may happen that the data service is requested to trigger an http call while a previous one hasn't yet…
Rodrigo Martinez
  • 913
  • 3
  • 13
  • 29
4
votes
2 answers

Retrieve Observable subscribers and make them subscribe to another Observable

Simply put Given an existing Observable (which has not completed yet), is there a way to retrieve associated subscribers (functions passed to subscribe) to make them subscribe to another Observable instead? Context A service in my application helps…
Stphane
  • 3,368
  • 5
  • 32
  • 47
3
votes
1 answer

How to properly run subscription inside finalize in rxjs

New to rxjs. Have a bit of a situation which I find confusing. The scenario is after clicking a button, a confirm modal would appear asking yes or no, then if the response is yes, the proceed to the switchMap call, and finally call a subscription at…
3
votes
1 answer

RxJS how to grab first values that is not null from two promises

I'm trying to wrap my head around how RxJS concat works, and how it works with Promises in general. I have two observables: currentConfirmation$ emits null newConfirmation$ emits a new confirmation Could someone explain why this works: const…
Deus Duke
  • 93
  • 1
  • 10
1
2
3
50 51