First thank you for your answer and I'm sorry to be late. This works onlu if I put $rootScope.$on inside function, but if I put it outside doesn't work I don't understand why.
2016-05-24 10:05 GMT+01:00 'Manish Pal' via AngularJS < [email protected]>: > Not sure, what $scope.$root is...but if you $broadcast it from > $rootScope, your other controller would get it. > in fact won't be a bad idea to do $rootScope.$emit and then other > controller listens to $rootScope.$on, that ways the event won't have to go > through all the scopes on your page. > > > On Friday, May 20, 2016 at 7:02:43 PM UTC+5:30, Imane Alfaqir wrote: >> >> Hi everybody, I'm trying to use $scope.$on and $rootScope.$broadcast in >> order to use a variable of a controller function in another controller >> function. I have already use this for other purpose, so my issue is the >> $scope.$on function isn't executing, I tried to make alert inside it but I >> didn't get any alert, I don't know what is the problem. Here is a snippet >> of my code to illustrate the issue. Thankx for advance :) >> >> >> app1.controller('autoCompleteCTRL',function($scope,$rootScope,$http) { >> $scope.$on("myEvent3", function (event, args) { >> alert(1); >> $scope.SearchNearPoint= args.value; >> >> $http({ >> method: "get", >> url: "path/to/file.php", >> dataType: 'json', >> params: { 'userText': $scope.searchText}, >> async: false >> >> }).success(function(data, status, headers, config) { >> $rootScope.suggestions = data; >> >> }).error(function(data, status, headers, config) { >> >> }); >> >> }); >> >> app1.controller('BasicCenterController', function($scope, leafletData, >> $http) { >> $scope.$root.$broadcast("myEvent3", { >> >> value: startLatLng >> >> }); >> >> });` >> >> >> >> -- > You received this message because you are subscribed to a topic in the > Google Groups "AngularJS" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/angular/ZA1V1Lswfm8/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/angular. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
