When I use broadcast to send data, I encounter an issue. Here is the code snippet:
$rootScope.$broadcast('myEvent',{
data:"value"
});
Now, here is my 'on' code:
$scope.$on('myEvent', (event, args) => {
$scope.data = args.data;
console.log($scope.data);
});
console.log($scope.data);
The problem arises when the console.log inside the function correctly displays the value, but outside it shows undefined. What could be causing this discrepancy? Any suggestions are appreciated. Thank you.