Observable.zip is not a function

吃可爱长大的小学妹 提交于 2019-12-23 07:22:41

问题


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",

回答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);
        });



回答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 => ...);



回答3:


5.5 rxjs:

import {zip} from "rxjs/observable/zip";
const zippedUsers: Observable<User[]> = zip(this.usersObservable);


来源:https://stackoverflow.com/questions/44002910/observable-zip-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!