Angular2与来自rxjs的combineAll

时间:2016-11-21 23:03:45

标签: angular observable

我试图使用来自可观察功能的combineAll,但我一直收到以下错误

TypeError: unknown type returned
at Object.subscribeToResult (http://164.132.97.206:10000/vendor.bundle.js:35082:27)
at CombineLatestSubscriber._complete (http://164.132.97.206:10000/main.bundle.js:39140:46)
at CombineLatestSubscriber.Subscriber.complete (http://164.132.97.206:10000/vendor.bundle.js:32309:18)
at MergeMapSubscriber.notifyComplete (http://164.132.97.206:10000/vendor.bundle.js:34474:30)
at InnerSubscriber._complete (http://164.132.97.206:10000/vendor.bundle.js:31646:21)
at InnerSubscriber.Subscriber.complete (http://164.132.97.206:10000/vendor.bundle.js:32309:18)
at CatchSubscriber.Subscriber._complete (http://164.132.97.206:10000/vendor.bundle.js:32327:26)
at CatchSubscriber.Subscriber.complete (http://164.132.97.206:10000/vendor.bundle.js:32309:18)
at MapSubscriber.Subscriber._complete (http://164.132.97.206:10000/vendor.bundle.js:32327:26)
at MapSubscriber.Subscriber.complete (http://164.132.97.206:10000/vendor.bundle.js:32309:18)
at XMLHttpRequest.onLoad (http://164.132.97.206:10000/vendor.bundle.js:21511:38)
at ZoneDelegate.invokeTask (http://164.132.97.206:10000/polyfills.bundle.js:18029:35)
at Object.onInvokeTask (http://164.132.97.206:10000/vendor.bundle.js:15519:37)
at ZoneDelegate.invokeTask (http://164.132.97.206:10000/polyfills.bundle.js:18028:40)
at Zone.runTask (http://164.132.97.206:10000/polyfills.bundle.js:17918:47)
at XMLHttpRequest.ZoneTask.invoke (http://164.132.97.206:10000/polyfills.bundle.js:18099:33)

以下是我使用某种方式

的代码部分
export interface VertexOperation {
  action: string,//add, erase, update
  mainVertex?: string,
  mainKey?: string,
  vertexName: string,
  edgeName: string,
  vertex: any,
  edge: any
}
public updateVertexEdge(operation:VertexOperation): Observable<QueryVertexConnection> {
    return this._http.post(this._userService.apiEndPoint+'updateLink/'+operation.vertexName, operation, {headers: this._userService.getHeaders()})
        .map(
            (response:Response) => {
                let res = response.json();
                console.log(res);
                return (res);
            })
            .catch((error:any) => Observable.throw(error.json().message || 'ServerErr'));
}
public updateEdges(items: Array<VertexOperation>) {
    console.log(items);
    return Observable.from(items).concatMap(
        (val) => {
            return this.updateVertexEdge(val);
        }
    ).combineAll();
}
this.updateEdges(vertexEdges).subscribe(
      (evResult) => {
        console.log(evResult);
      },
      (errEv) => {
        console.log(errEv);
      }
    );

对api端点的调用没有任何问题,更新已完成,但我一直收到此错误,我不确定我是否未正确使用combineAll,我&# 39;我已经阅读了stackoverflow上的一些帖子,因为我这样使用它,所以我不确定这有什么问题。 如果有人有类似的问题或有更好的方法来结合某些要求我真的很感激,如果你能分享你的知识:)

1 个答案:

答案 0 :(得分:0)

您应该使用map代替concatMap

错误显示combineAll收到错误的类型。 combineAll期待Observable of Observables,而concatMap返回Observable

这样的事情:

public updateEdges(items: Array<VertexOperation>) {
    console.log(items);
    return Observable.from(items).map(
        (val) => {
            return this.updateVertexEdge(val);
        }
    ).combineAll();
}