Below I have a factory called Position that returns data that the whole app needs to use about the users current position and other models. Under that is a service called Romanize that contacts an external URL which provides a kind of translation, but Romanize needs to access to the app data provided by Position. I tried with the usual DI but it fails. How can I inject Position into Romanize as a dependency?
app.factory('Position', function(){
return{
questionNumber: 0,
tutorialNumber: 0,
sectionNumber: 0,
sections: sections
}
});
app.factory('Romanize', ['$http', 'Position', function($http){
alert(Position);
return{
Position: Position,
get: function(){
$http.get(Position.sections[Position.sectionNumber].romanizeService).success(function(data) {
return data;
});
}
};
}]);
You missed to add Position as a parameter in the Romanize factory function.
app.factory('Romanize', ['$http', 'Position', function($http, Position){
The string 'Position', tells Angular to inject the position service as the second argument (the $http service being the first).