Thanks Johnathan
For a quick workaround I just used ripped the code straight out of the
(thankfully short) UserService.get() function.
The injector looks by far a better solution.
Many thanks, again
Normykins
On Sunday, 12 October 2014 11:51:56 UTC+1, Norman Potter wrote:
>
> Hey peeps
>
> Got a bit of a problem with a circular dependency that I'm struggling with.
>
> Can anyone help me get around this problem.
>
> The error I get is
>
> Circular dependency found: $http <- UserService <- RequestTransformer <-
> $http <- $compile
>
>
> I have a request transformer...
> app.factory('RequestTransformer', [
> 'config', 'UserService',
> function(config, UserService) {
>
> return {
> request: function(config) {
> var user = UserService.get();
> if (user) config.headers['x-user-token'] = user.id;
> config.headers['x-api-key'] = config.apikey;
> config.headers['x-api-version'] = config.apiversion;
> return config;
> }
> }
>
> }
> ]);
>
> and a UserService (truncated for brevity)
>
> app.factory('UserService', [
> '$http', '$q', 'config', 'LocalStorageService', 'AppDataService',
> function($http, $q, config, LocalStorageService, AppDataService) {
>
> return {
> login: function(email, password) {
> var deferred = $q.defer();
> $http({
> method: 'post',
> url: '/login',
> data: {
> email: email,
> password: password
> }
> })
> .success(function(response, status, headers, config) {
> deferred.resolve(angular.fromJson(response));
> })
> .error(function(response, status, headers, config) {
> deferred.reject(angular.fromJson(response));
> });
>
> return deferred.promise;
> }
> ]);
>
>
> Any help greatly appreciated
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.