【发布时间】:2015-08-04 11:01:42
【问题描述】:
以下页面有一个示例,用于在角度委派 $log 的调试功能。
http://solutionoptimist.com/2013/10/07/enhance-angularjs-logging-using-decorators/
同样,我想委托 $http 服务的获取/发布功能。这样我就可以记录我的应用所做的所有请求。
下面是我的代码
$provide.decorator('$http', ["$delegate", function($delegate) {
var debugFn = $delegate.get;
$delegate.get = function() {
var args = [].slice.call(arguments);
// Prepend timestamp
console.log(args[0]);
// Call the original with the output prepended with formatted timestamp
debugFn.apply(null, args)
};
return $delegate;
}]);
即使它正在记录 url,它也会在此之后引发异常
TypeError: Cannot read property 'finally' of undefined
at handleRequestFn (angular.js:17382)
at compileTemplateUrl (angular.js:8270)
at applyDirectivesToNode (angular.js:7885)
at compileNodes (angular.js:7431)
at compile (angular.js:7338)
at applyDirectivesToNode (angular.js:7808)
at compileNodes (angular.js:7431)
at compileNodes (angular.js:7443)
at compile (angular.js:7338)
at angular.js:1630
我错过了什么?
【问题讨论】: