I have one common controller, this controller contains one method. I need to call this controller method from another service. Is it possible.
My code example: This is my Root Controller and its containing function called myFunction
app.controller('rootController', function($rootScope,$scope,$on) { $scope.$on("func_call", function(event, args) { var p = args.myParam;
This is my service, from this service I need to call a function in the root controller
app.factory('anotherService', function($rootScope,$broadcast){ $rootScope.$broadcast("func_call", { myParam: {} }); });
I tried calling the Root Controller function from the $rootScope.myFunction ("called") , but it did not work. Anyone please suggest a better way to call the root controller function from the service
source share