0

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?

2
  • can you post the code that use you use with $location and Restangular such as myApp.factory('RootService', ['Restangular','$location', function(Restangular,$location) { ... }]); Commented Mar 10, 2014 at 19:01
  • @DavidChase I tried the declaration in your comment and AngularJS did not break. If you leave something similar as an answer, I'll mark it as the accepted answer if my Restangular tests work, too. Commented Mar 10, 2014 at 19:10

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

it should be okay to define your factory like this

app.factory('RootService', ['Restangular','$location', function(Restangular,$location) {
  ...
}]);

here is a working PLUNKER example...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.