Skip to content

Instantly share code, notes, and snippets.

@kalisjoshua
Last active January 2, 2016 19:49
Show Gist options
  • Save kalisjoshua/8352674 to your computer and use it in GitHub Desktop.
Save kalisjoshua/8352674 to your computer and use it in GitHub Desktop.
Angular Service Dependencies

Angular Service Dependencies

I am trying to make one Service (SecondService) a dependency of another (FirstService), where the result from one is going to joined with portions of another.

Disclaimer: I have about 8-10 hours of total AngularJS experience.

angular.module('app')
.service('FirstService', ['$q', 'SecondService', function ($q, SecondService) {
'use strict';
var deferred = $q.defer(),
model;
model = {
// ..
// use SecondService here
};
deferred.resolve(model);
return deferred.promise;
}]);
angular.module('app')
.service('SecondService', ['$q', function ($q) {
'use strict';
var deferred = $q.defer(),
model;
model = {
// ..
};
deferred.resolve(model);
return deferred.promise;
}]);
@daspecster
Copy link

function myModuleCfgFn($provide) {
  $provide.factory('myService', ['dep1', 'dep2', function(dep1, dep2) {}]);
}

from http://docs.angularjs.org/guide/dev_guide.services.managing_dependencies

@daspecster
Copy link

Based on this, I think what you have there should work? http://docs.angularjs.org/api/AUTO.$provide#methods_service

@kalisjoshua
Copy link
Author

I must be missing something else then.

@Vp3n
Copy link

Vp3n commented Jan 10, 2014

I don't know if i understand your need correctly but, if you need to use combine results in a new promise you could just do that : http://plnkr.co/edit/9MRNBZMPJgLFnJP1PQIm?p=preview

Let me know if it answer your question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment