2016-11-21 84 views
0

我試圖從可觀察的功能使用combineAll,但我不斷收到以下錯誤Angular2與combineAll從rxjs

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,我已閱讀了一些在stackoverflow上的帖子它在那裏被使用,所以我不確定這是什麼錯誤。 如果任何人有類似的問題或有一些更好的方式結合一些請求,我會非常感謝,如果你能分享你的知識:)

回答

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(); 
} 
+0

我看到:d謝謝! – Darksorrow