Observable.zip is not a function

10,448

Solution 1

maybe something like

import {Observable} from "rxjs/Observable";
import "rxjs/add/observable/zip";

then something like:

Observable.zip(this.someProvider.getA(), this.someProvider.getB())
        .subscribe(([a, b]) => {
            console.log(a);
            console.log(b);
        });

Solution 2

RxJS 6

Starting from RxJS 6...

Observable creation functions

such as from(), fromPromise(), of(), zip() should be imported like this:

import { from, fromPromise, of, zip } from 'rxjs';

and used as a plain function call:

const data: Observable<any> = fromPromise(fetch('/api/endpoint'));

Pipeable operators

should be imported like this:

import { map, filter, scan } from 'rxjs/operators';

and used as pipe() method arguments:

const someObservable: Observable<number> = ...;
const squareOddVals = someObservable.pipe(
        filter((n: number) => n % 2 !== 0),
        map(n => n * n))
    .subscribe((n: number): void => ...);

Solution 3

5.5 rxjs:

import {zip} from "rxjs/observable/zip";
const zippedUsers: Observable<User[]> = zip(this.usersObservable);
Share:
10,448
KarolDepka
Author by

KarolDepka

Passionate software developer &amp;&amp; entrepreneur, mostly interested in stuff like Angular, TypeScript, Firebase, Firestore, Android, hybrid mobile apps, Java, MPS, Kotlin, Scala, C#, ...

Updated on June 09, 2022

Comments

  • KarolDepka
    KarolDepka about 2 years

    VM95422:27 ORIGINAL EXCEPTION: WEBPACK_IMPORTED_MODULE_3_rxjs_Observable.Observable.zip is not a function

    Tried various imports

    // import 'rxjs/add/operator/zip';
    // import 'rxjs/add/observable/zip-static';
    // import 'rxjs/add/operator/zip';
    import 'rxjs/operator/zip';
    

    Trying to use it like that:

    const zippedUsers: Observable<User[]> = Observable.zip<User>(this.usersObservable);
    

    Angular 4, TypeScript 2.1.6

    package.json:

    "rxjs": "^5.1.0",
    
  • Ingo Bürk
    Ingo Bürk almost 6 years
    The question explicitly mentions rxjs 5, so this doesn't provide an answer to the question.
  • Alexander Abakumov
    Alexander Abakumov almost 6 years
    @IngoBürk: I believe RxJS 5 was just the version OP was using at the time of asking (more than 2yrs ago). Nowadays, I think it's more beneficial for the community if this question is kept in-sync with the current versions of libs especially taking into account this is the top question in Google search for the matter.
  • Alexander Abakumov
    Alexander Abakumov almost 6 years
    @IngoBürk: Also, notive this answer which provides information related to RxJS 5.5 which also is a higher version than OP asked. But nobody has been complaining half a year already :)
  • Alexander Kozachenko
    Alexander Kozachenko over 5 years
    @AlexanderAbakumov thanks a lot: import from accepted answer stopped working after update 6->7, import { Observable } from 'rxjs'; works
  • qu1j0t3
    qu1j0t3 almost 5 years
    I spent more than 90 minutes trying to find this solution. None of the material or documentation I found by google helped. But your answer did.