装饰角$ http时出错

时间:2015-09-15 02:47:57

标签: angularjs http decorator angular-decorator

我正在尝试实现$ http.get()的简单装饰器。在调用get()之后,我想将返回promise转给我自己的服务ProgressBar。 (我的服务在控制器中工作正常,FWIW。)

$provide.decorator('$http',function($delegate,ProgressBar){
  //GET
  var tempGet=$delegate.get;
  $delegate.get=function(){
    var args    = Array.prototype.slice.apply(arguments)
    var httpPromise=tempGet.apply(undefined,args);//(arguments[0],arguments[1]);
    ProgressBar.inProgressAsync(httpPromise);
  };
  return $delegate;
});

然而,我收到以下错误。

Error: undefined is not an object (evaluating '$http.get(tpl, httpOptions)
        ['finally']')
handleRequestFn@http://localhost:9000/bower_components/angular/angular.js:17554:41
ngIncludeWatchAction@http://localhost:9000/bower_components/angular/angular.js:24143:29
constantListener@http://localhost:9000/bower_components/angular/angular.js:14276:25
$digest@http://localhost:9000/bower_components/angular/angular.js:15715:31
$apply@http://localhost:9000/bower_components/angular/angular.js:15986:31
bootstrapApply@http://localhost:9000/bower_components/angular/angular.js:1658:21
invoke@http://localhost:9000/bower_components/angular/angular.js:4473:22
doBootstrap@http://localhost:9000/bower_components/angular/angular.js:1656:20
bootstrap@http://localhost:9000/bower_components/angular/angular.js:1676:23
angularInit@http://localhost:9000/bower_components/angular/angular.js:1570:14
http://localhost:9000/bower_components/angular/angular.js:28683:16
fire@http://localhost:9000/bower_components/jquery/dist/jquery.js:3148:35
fireWith@http://localhost:9000/bower_components/jquery/dist/jquery.js:3260:11
ready@http://localhost:9000/bower_components/jquery/dist/jquery.js:3472:24
completed@http://localhost:9000/bower_components/jquery/dist/jquery.js:3503:15

我认为(?)我正在改变http请求,但我看不清楚如何。有什么想法吗。谢谢。

0 个答案:

没有答案
相关问题