How can I send my $scope
object from one controller to another using .$emit
and .$on
methods?
function firstCtrl($scop
I would additionally suggest a 4th option as a better alternative to the proposed options by @zbynour.
Use $rootScope.$emit
rather than $rootScope.$broadcast
regardless of the relationship between trasmitting and receiving controller. That way, the event remains within the set of $rootScope.$$listeners
whereas with $rootScope.$broadcast
the event propagates to all children scopes, most of which will probably not be listeners of that event anyway. And of course in the receiving controller's end you just use $rootScope.$on
.
For this option you must remember to destroy the controller's rootScope listeners:
var unbindEventHandler = $rootScope.$on('myEvent', myHandler);
$scope.$on('$destroy', function () {
unbindEventHandler();
});