125. $rootScope.$broadcast
Import
·
Jun 10, 2024
·
article
You can use $rootScope.$broadcast to notify other widgets and $rootScope.$on to receive the notification
FIRING AN EVENT:
Go to your desired widget and on the client controller do something like this
TIPS:
- It is also great if you will put a 500 milliseconds timeout to broadcast just to ensure that all other widgets are loaded and ready to listen when we broadcast an event.
- The event name can be anything you want just come up with a name with a unique identifier
- Data can also be a JSON object. In this case, it’s just a string.
LISTENING TO AN EVENT
Go to your next widget where you want to listen to the event that you created and do something like this
This can be very useful when you want to send data to other widgets.
View original source
https://medium.com/@LearnITbyPrashant/125-rootscope-broadcast-a3b651536aaa?source=rss-d005fc598f0a------2