- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2025 03:51 AM
Hi everyone,
I’m working on a ServiceNow scoped application with multiple widgets, and I’m exploring using $rootScope.$broadcast to communicate events between widgets. I’m aware that improper use can lead to performance issues or scope pollution.
I’d like to know the best practices for using $rootScope.$broadcast in ServiceNow widgets, specifically:
How to safely communicate events between widgets
Patterns to avoid scope or memory issues
Recommended alternatives for inter-widget communication in scoped applications
Any advice, examples, or lessons from real-world usage would be very helpful!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2025 01:19 AM
Sure @Onlyprashant,
Here are some links that may help you:
- https://www.servicenow.com/c ommunity/developer-forum/using-angular-service-providers-in-service-por...
- https://developer.servicenow.com/dev.do#!/learn/learning-plans/xanadu/servicenow_application_develop...
hope this helps!
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution and helpful so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2025 07:34 AM
Hi @Onlyprashant,
The best practice is to always use uniquely prefixed event names (e.g., my-app.item.updated) and to listen for these events with $scope.$on in your widget's client controller, as this automatically unregisters the listener when the widget is destroyed, preventing memory leaks. For simpler communication, especially between a parent and embedded widgets, passing data through the widget options object is a cleaner method.
However, the most robust and scalable alternative is to create a shared Angular Service (using an Angular Provider record in ServiceNow). This service can be injected into your widget controllers, allowing them to share data and methods directly without broadcasting events, leading to a more structured and maintainable application.
Official reference on Angular Providers:
Hope this helps!
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution and helpful so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2025 04:31 AM
Hi @Community Alums , could you please provide a reference or example of an Angular service? I attempted to create one, but it isn’t working as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2025 01:19 AM
Sure @Onlyprashant,
Here are some links that may help you:
- https://www.servicenow.com/c ommunity/developer-forum/using-angular-service-providers-in-service-por...
- https://developer.servicenow.com/dev.do#!/learn/learning-plans/xanadu/servicenow_application_develop...
hope this helps!
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution and helpful so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2025 01:05 AM
@Community Alums Thanks for sharing these resources, really appreciate it!
