0

This is the factory code under the myApp module

angular.module('myApp')
        .factory('userFactory', ['$http', function ($http) {

            var userFactory = {};

            userFactory.login = function (user) {
                return $http.post(sc.getDomain() + 'session/create', user);
            };

            return userFactory;
        }]); 

and the controller is under the myApp.user module

angular.module('myApp.user',[])

.controller('loginCtrl', ['$scope', function ($scope) {

}]);

and this is the main app level module with myApp.user injected -

angular.module('myApp', ['ngRoute','myApp.user']). //etc

How would I access the factory in the "myApp" module from the controller which is in the "myApp.user" module?

1
  • are you sure you want two apps? Commented Sep 24, 2014 at 14:37

1 Answer 1

2

myApp.user depends on myApp. So myApp should be set as a dependency of myApp.user instead.

However, this will probably not end up in clean code and I'm not sure how circular dependencies are handled. You should move the userFactory to myApp.user instead.

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

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.