In my application, I am writing a decorator for $logso that I can configure functions $log, including calling a third-party service. A third party service introduces $qfor its internal actions. Now this causes a cyclic dependency error:
Uncaught Error: Circular dependency: $q <- tploggerService <- $log <- $exceptionHandler <- $rootScope.
Because it qProvideruses exceptionHandlerProvider, which ultimately uses logProvider, which, it seems to me, causes this. Has anyone encountered similar problems with decorating and is there a solution to work on this or another template to solve this problem?
Here is a simple code demo, rate your help:
angular.module('SomeThirdPartyApp', []);
tploggerService.$inject = ['$q'];
function tploggerService ($q) {
this.info = function (data) {
var deferred = $q.defer();
};
}
angular.module('SomeThirdPartyApp').service('tploggerService', tploggerService);
angular.module('decorApp', ['SomeThirdPartyApp']);
angular.module('decorApp').config([
'$provide', function ($provide) {
$provide.decorator('$log', ['tploggerService','$delegate',
function (tploggerService, $delegate) {
var _info = $delegate.info;
$delegate.info = function(){
var args;
var customlogmessage;
tploggerService.info(customlogmessage);
_info.apply(null, args);
}
return $delegate;
}]);
}]);