Tracing calls in AngularJS
I recently had a problem where I would sometimes pass null URLs to $http.get. With promises all over the place, it's not always easy to trace where the bad data comes from.
That is, until you start playing with decorators. For example, you can log all HTTP requests with:
ngApp.config(function ($provide) {
$provide.decorator('$http', function ($delegate) {
var _get = $delegate.get;
$delegate.get = function () {
console.log.apply(console, arguments);
return _get.apply(this, arguments);
};
return $delegate;
});
});
Written by Laurent Perrin
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Debug
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#