Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Observable.zip is not a function

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",
like image 837
KarolDepka Avatar asked May 16 '17 13:05

KarolDepka


3 Answers

5.5 rxjs:

import {zip} from "rxjs/observable/zip";
const zippedUsers: Observable<User[]> = zip(this.usersObservable);
like image 173
Николай Роговой Avatar answered Oct 20 '22 10:10

Николай Роговой


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);
        });
like image 43
Patrioticcow Avatar answered Oct 20 '22 08:10

Patrioticcow


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 => ...);
like image 31
Alexander Abakumov Avatar answered Oct 20 '22 09:10

Alexander Abakumov