How can I access a variable set in an event?
Here is the code snippet:
$scope.$on('event_detail', function (event, args) {
$scope.id = args;
console.log($scope.id); // This prints the correct value
});
console.log($scope.id); // This returns undefined
When trying to display "$scope.id" in the console, it shows "undefined". Is there a way to access the variable outside of the $scope.$on function?
This is my broadcast function:
$scope.showDetail = function (data) {
$rootScope.$broadcast("event_detail", data.id_case);
$location.path("/detailcase/" + data.id_case);
};