Reputation: 619
based on this reply link I tried to send a data when I click on a button and call a method from Controller1 to Controller2 this is my try:
Controller1:
$scope.DetailsLivraison = function(){
var idv = $scope.idBonSortie;
$rootScope.$emit("CallParentMethod", idv);
}
Controller2:
$rootScope.$on("CallParentMethod", function(){
$scope.parentmethod(idv);
});
$scope.parentmethod = function(idv) {
//Data traitment
}
my problem is that,the method in the second controller is not called,I have defined $rootscope in both controllers any help please to solve the problem thanks for help
Upvotes: 0
Views: 117
Reputation: 4543
Firstly, to make this happen both your controllers should be active at that time.
Secondly, you can use the code below:
$rootScope.$broadcast('CallParentMethod', { //can also use $emit
idv: idv,
});
At the receiving end in the other controller:
$rootScope.$on('CallParentMethod', function(event, args) {
$scope.parentmethod(args.idv);
});
Upvotes: 1