2017-01-24 82 views
1

試圖重試(與回退邏輯)時,錯誤的http.getretryWhen與退避

return this.http.get(this.urlToBackend) 
      .map((res: Response) => res.json()) 
      .retryWhen(errors => 
       errors 
        .zip(Observable.range(3, 15), (_, i) => i) 
        .flatMap(i => { 
         if (i >= 15) { 
          throw errors; 
         } 
         let t = (Math.pow(2, i)) * 1000; 
         return Observable.timer(t); 
        })) 
      .catch((error: any) => this.handleError(error, false, 0, this.urlToBackend)); 

請收到此錯誤:

TypeError: this.http.get(...).map(...).retryWhen is not a function 
    at IOService.getUserDetails (http://localhost:4200/main.bundle.js:303:14) 
    at NavirComponent.ngOnInit (http://localhost:4200/main.bundle.js:3328:24) 
    at Wrapper_NavirComponent.ngDoCheck (/AppModule/NavirComponent/wrapper.ngfactory.js:22:53) 
    at CompiledTemplate.proxyViewClass.View_AppWrapperComponent0.detectChangesInternal (/AppModule/AppWrapperComponent/component.ngfactory.js:100:28) 
    at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:4200/vendor.bundle.js:81933:14) 
    at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:4200/vendor.bundle.js:82128:44) 
    at CompiledTemplate.proxyViewClass.AppView.internalDetectChanges (http://localhost:4200/vendor.bundle.js:81918:18) 
    at CompiledTemplate.proxyViewClass.View_AppWrapperComponent_Host0.detectChangesInternal (/AppModule/AppWrapperComponent/host.ngfactory.js:29:19) 
    at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:4200/vendor.bundle.js:81933:14) 
    at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:4200/vendor.bundle.js:82128:44) 
    at ViewRef_.detectChanges (http://localhost:4200/vendor.bundle.js:60587:20) 
    at http://localhost:4200/vendor.bundle.js:41131:67 
    at Array.forEach (native) 
    at ApplicationRef_.tick (http://localhost:4200/vendor.bundle.js:41131:25) 
    at ApplicationRef_._loadComponent (http://localhost:4200/vendor.bundle.js:41106:14) 
+1

有你輸入了嗎? –

回答

2

嘗試添加進口

import "rxjs/add/operator/mergeMap"; 
+0

啊!我正在移動的方法,並錯過了進口它..和VS編碼是安靜的..謝謝! –