Why the return value of angular $on cannot be assigned

problem description

angular broadcasts a data in the controller using $scope.$emit (), and accepts that assigning a variable to a variable is always undefined using $scope in other controllers.

related codes

$scope.$emit ("changeData", 0); / / broadcast a changeData variable upwards in controller 1 with a value of 0

$scope.$on ("changeData", function (event,data) {

    console.log(data);   //data
    $scope.componentRturn=data;   //

});
console.log ($scope.componentRturn); / / undefinde
/ / Controller 2 to accept

what is this situation, and what should I do when I use this broadcast value outside the $0n () method?

Aug.29,2021
Menu