angularjs - accessing a factory from a controller in another module

deez22

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?

Remco Haszing

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Accessing factory defined in another module in angularjs

From Dev

Accessing a service from a controller in another file in AngularJS

From Dev

Accessing a service from a controller in another file in AngularJS

From Dev

AngularJS - Injecting factory from another module into a provider

From Dev

AngularJS Inject factory into another factory from the same module

From Dev

AngularJS Inject factory into another factory from the same module

From Dev

Call function from one controller to another controller using Factory in Angularjs

From Dev

Call a controller function of one module from controller of another module in angularjs

From Dev

Accessing $scope variable from another method in the same controller Angularjs

From Java

Can an AngularJS controller inherit from another controller in the same module?

From Dev

AngularJS: Inject controller inside another controller from the same module

From Dev

Access angularjs controller from factory angularjs

From Dev

From an AngularJS controller, how do I resolve another controller function defined in the module (dynamic ng-controller)?

From Dev

angularjs - Accessing ui-bootstrap modal dismiss and close function from another controller

From Dev

Accessing a controller from inside a callback function in AngularJS

From Dev

AngularJS Accessing Aliased Controller Attribute From Directive

From Dev

Accessing a controller from inside a callback function in AngularJS

From Dev

AngularJS - accessing elements inside a controller from a service

From Dev

Accessing $scope in AngularJS factory?

From Dev

Pass authentication error from factory to controller in AngularJS

From Dev

Passing multiple parameters from controller to factory in angularjs

From Dev

How to pass functions from factory into controller angularJS

From Dev

how to recover data from factory to controller angularjs

From Dev

Passing parameter from view to controller to factory in AngularJS

From Dev

AngularJs call controller function from factory

From Dev

Accessing data from one controller to another

From Dev

Accessing the variable from another model in my controller

From Dev

Accessing data from another controller in Rails

From Dev

How to convert this AngularJS controller in this module to another format?

Related Related

  1. 1

    Accessing factory defined in another module in angularjs

  2. 2

    Accessing a service from a controller in another file in AngularJS

  3. 3

    Accessing a service from a controller in another file in AngularJS

  4. 4

    AngularJS - Injecting factory from another module into a provider

  5. 5

    AngularJS Inject factory into another factory from the same module

  6. 6

    AngularJS Inject factory into another factory from the same module

  7. 7

    Call function from one controller to another controller using Factory in Angularjs

  8. 8

    Call a controller function of one module from controller of another module in angularjs

  9. 9

    Accessing $scope variable from another method in the same controller Angularjs

  10. 10

    Can an AngularJS controller inherit from another controller in the same module?

  11. 11

    AngularJS: Inject controller inside another controller from the same module

  12. 12

    Access angularjs controller from factory angularjs

  13. 13

    From an AngularJS controller, how do I resolve another controller function defined in the module (dynamic ng-controller)?

  14. 14

    angularjs - Accessing ui-bootstrap modal dismiss and close function from another controller

  15. 15

    Accessing a controller from inside a callback function in AngularJS

  16. 16

    AngularJS Accessing Aliased Controller Attribute From Directive

  17. 17

    Accessing a controller from inside a callback function in AngularJS

  18. 18

    AngularJS - accessing elements inside a controller from a service

  19. 19

    Accessing $scope in AngularJS factory?

  20. 20

    Pass authentication error from factory to controller in AngularJS

  21. 21

    Passing multiple parameters from controller to factory in angularjs

  22. 22

    How to pass functions from factory into controller angularJS

  23. 23

    how to recover data from factory to controller angularjs

  24. 24

    Passing parameter from view to controller to factory in AngularJS

  25. 25

    AngularJs call controller function from factory

  26. 26

    Accessing data from one controller to another

  27. 27

    Accessing the variable from another model in my controller

  28. 28

    Accessing data from another controller in Rails

  29. 29

    How to convert this AngularJS controller in this module to another format?

HotTag

Archive