Communication between controllers is performed, although the methods are $emit + $on / $broadcast + $on .
So, in your case, you want to call the controller method "One" inside the controller "Two", the correct way to do this:
app.controller('One', ['$scope', '$rootScope' function($scope) { $rootScope.$on("CallParentMethod", function(){ $scope.parentmethod(); }); $scope.parentmethod = function() { // task } } ]); app.controller('two', ['$scope', '$rootScope' function($scope) { $scope.childmethod = function() { $rootScope.$emit("CallParentMethod", {}); } } ]);
While $rootScope.$emit , you can send any data as a second parameter.
Yashika Garg Apr 6 '15 at 9:23 2015-04-06 09:23
source share