1

in ControllerOne

$scope.displayReport = function( status ){

   statusCkeck( status ) ;
}

statusCkeck() ; is in another controller -controllerTwo

How can i call this function from one controller to another

i tried angular.element(document.getElementById('controllerTwo')).scope().statusCheck();

But it throwing error.

Please suggest

Prashobh
  • 9,216
  • 15
  • 61
  • 91

2 Answers2

7

You should use a service instead to avoid muddying up the controllers with code that calls functions in other controllers. If you're sharing functions, just define them in a service and inject that service where needed.

angular.module('myApp', [])
  .factory('myService', function() {
    return {
      sharedFunction: function (foo, bar) {
        return foo + bar;
      }
    }
};
thomastuts
  • 3,459
  • 3
  • 20
  • 28
1

You can get scope:

angular.element(document.getElementById('yourControllerElementID')).scope().get()

But yourControllerElementID should be ElementID not ControlerName!

For example:

<div id="elemID" ng-controller="YourController"></div>

So elemId is id of element with YourController.

Norbert Pisz
  • 3,392
  • 3
  • 27
  • 42