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
Did you know?
AngularJS pages are long-lived browser apps with the same script risk as a newer single-page app. Third-party code in the template can read forms and values rendered on the page.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#