Reputation: 1972
I have the following factory. I use it to store lists of tabs in various parts of my program.
myApp.factory('RootService', function($location) {
var tabList = [ ... ];
var loginTabList = [ ... ];
return {
setTabList: function(data) {
tabList = data;
},
getTabList: function(data) {
if ($location.path() !== '/login') { return tabList; }
else {
if (data === 0) { return loginTabList; }
else { return tabList; }
}
}
};
});
I wanted to move the initialization of these lists to my Java layer so that I can have them populate from an Oracle database. I have the back-end sorted out, but when I attempt to inject Restangular into the factory so that I can use it, the factory prevents AngularJS from functioning at all. With minor changes, I can get AngularJS to work again with one:
myApp.factory('RootService', function($location) { ... });
Or the other:
myApp.factory('RootService', ['Restangular', function(Restangular) { ... }]);
declarations but not both. Am I declaring the factory incorrectly? How can I use both Restangular and $location together?
Upvotes: 0
Views: 1311
Reputation: 5857
it should be okay to define your factory like this
app.factory('RootService', ['Restangular','$location', function(Restangular,$location) {
...
}]);
here is a working PLUNKER example...
Upvotes: 1
Reputation: 2073
Try using the following:
myApp.factory('RootService', ['Restangular','$location',
function(Restangular, $location) {
...
}]);
It is possible that you didnt use the inline annotation for both $location
and Restangular
more on that here
Upvotes: 1