2017-01-24 73 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编码是安静的..谢谢! –