Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 08:53 AM
@kali
My apologies I misread your message I thought you were asking for a simple code for $scope.on and destroy.
I added a $scope.broadcast to the previous code to show how it works.
$scope.broadcastCustomEvent = function() {
var eventData = { message: 'This is a custom event!' };
$scope.$broadcast('custom.event', eventData);
console.log('Custom event broadcasted with data:', eventData);
};
// Listen for a custom event
$scope.$on('custom.event', function(event, data) {
console.log('Custom event received with data:', data);
// Handle the event
});
// Clean up when the scope is destroyed
$scope.$on('$destroy', function() {
console.log('Widget scope is being destroyed, cleaning up...');
// Perform cleanup actions
});
}