Observable.zip is not a function
Asked Answered
T

3

12

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",
Toxin answered 16/5, 2017 at 13:29 Comment(3)
import "rxjs/add/observable/zip";Sinuosity
reactivex.io/rxjs/manual/installation.htmlSinuosity
Could you consider changing the accepted answer since it's no longer correct for the recent RxJS versions?Aachen
M
25

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);
        });
Manakin answered 21/9, 2017 at 4:10 Comment(0)
A
9

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 => ...);
Aachen answered 10/8, 2018 at 19:50 Comment(4)
The question explicitly mentions rxjs 5, so this doesn't provide an answer to the question.Pentastich
@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.Aachen
@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 :)Aachen
@AlexanderAbakumov thanks a lot: import from accepted answer stopped working after update 6->7, import { Observable } from 'rxjs'; worksSaporous
O
8

5.5 rxjs:

import {zip} from "rxjs/observable/zip";
const zippedUsers: Observable<User[]> = zip(this.usersObservable);
Overgrowth answered 19/12, 2017 at 8:15 Comment(1)
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.Corson

© 2022 - 2024 — McMap. All rights reserved.