Last Updated: February 25, 2016
·
963
· lperrin

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;
  });
});