Also Controllers can be attached to the DOM in different ways. AngularJs call one method of controller in another controller .
There can be multiple some difficlut situations where you may want a simple parent and child controller to be able to communicate with other main and sub controllers in your AngularJs Application.
Step : 1. $rootScope.$emit() and $rootScope.$broadcast()
how to call one controller from another controller in angularjs
Step : 5.Kind of hack – with the help of angular.element()
id='Product' ng-controller='ProductCtrl'>{{varProduct}}
ng-click='getValueFromcategory()'>Click to get ValueFormcategory
id='category' ng-controller='categoryCtrl'>{{varcategory}}
ng-click='getValueFromProduct()'>Click to get ValueFormProduct
how to call one controller from another controller in angularjs
app.controller('ProductCtrl',function($scope){
$scope.varProduct="First Product";
$scope.getValueFromcategory=function(){
var categoryScope=angular.element('#category').scope();
console.log(categoryScope.varcategory);
}
});
app.controller('CarentCtrl',function($scope){
$scope.varcategory="First category";
$scope.getValueFromProduct=function(){
var ProductScope=angular.element('#Product').scope();
console.log(ProductScope.varProduct);
}
});