logo

NJP

Service Portal: Widget Communication

Import · Jan 05, 2021 · article

For the most part, widgets on the service portal are very self-contained. Widgets have their own scope, and most of their operations are contained within that scope. However, when developing custom widgets in the Service Portal, you may have the need to pass information from one widget on your page to a second widget on that same page. This can be done using a few angular methods: $broadcast, $emit, and $on. Let’s talk about what these methods do.$broadcast and $emit are both methods that allow you to raise an event in your widget. The difference between the two is the direction of the event. $broadcast sends an event downwards from parent to child controllers, while $emit sends an event upwards from the current controller to all of its parent controllers. You can then subscribe to an event using the $on event handler.Let’s walk through an example. Say you have “Widget 1”. Widget 1 will allow the user to click a button. Once the button has been clicked, the widget will use $broadcast to pass an object to “Widget 2.” So let’s look at what the client controllers for both these widgets would look like.

Widget 1

View original source

https://finite-partners.com/service-portal-widget-communication/