AngularJS $http and logger Circular Dependency
Error
[$injector:cdep] Circular dependency found: $rootScope <- $http <- logger <- $exceptionHandler <- $rootScope <- $location <- routehelper
TLDR:
If you are looking for RequireJS's easy way to late-bind a dependency, here's how you do it in AngularJS.
Story
I imagine this could be a fairly common scenario.
You implemented AngularJS, with a logger service.
You want to try to catch errors and log it back to your webservice
So add a REST call.
Error!
[$injector:cdep] Circular dependency found: $rootScope <- $http <- logger <- $exceptionHandler <- $rootScope <- $location <- routehelper
I actually quite like this error. It's telling me the dependency tree starting from routehelper and looping around to $rootScope
Bingle will tell you to re-architect your solution so you have proper separation of concerns. But to be honest, I just want to log an error…
So here's how you do it.