Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

RxJs observe several observables

In an older version of RxJs I used the following approach:

combineLatest([
  this.state.select(selector1),
  this.stage.select(selector2)
])
  .pipe(...)
  .subscribe(values => {
    const parameter: any = values[0];
    const data: any = values[1];
   );

In my new project I’m using RxJs 7.5 and this is not possible anymore.

combineLatestWith([
  this.userData.controls["name"].valueChanges,
  this.userData.controls["lastName"].valueChanges,
  this.userData.controls["age"].valueChanges,
  this.userData.controls["birthDate"].valueChanges])
.subscribe((result:any) => {

);

The compiler says: "Property ‘subscribe’ does not exist on type ‘OperatorFunction<unknown, [unknown, any]>’."

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The following snipped looks kind of ugly:

this.userData.controls["name"].valueChanges.combineLatestWith([
  this.userData.controls["lastName"].valueChanges,
  this.userData.controls["age"].valueChanges,
  this.userData.controls["birthDate"].valueChanges])
  .subscribe((result: any) => {
    console.log(result);
  });

Is there another solution, similar to the first approach?

>Solution :

You’re using wrong combineLatest() import. Since RxJS 7.0 the creation operator is called combineLatest() and is imported from 'rxjs' (this is the one you want to use).

import { combineLatest } from 'rxjs';

...

combineLatest([firstTimer, secondTimer]).subscribe(...);

combineLatestWith() is a pipable operator meant to be used inside RxJS chains (thus the error).

import { combineLatestWith } from 'rxjs';

...

input1Changes$.pipe(
  combineLatestWith(input2Changes$),
  map(([e1, e2]) => ...)
)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading