$rootScope.$broadcast - confusing argument
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2020 06:15 AM
Hello,
in my service portal widget I have this client script snippet of code:
$scope.copyFromPreviousTimesheet = function(){
$rootScope.$broadcast('tcp.copy.timesheet');
};
This is triggered by clicking a button - please see below snippet of HTML template:
<button type="button" class="btn" ng-click="copyFromPreviousTimesheet()" aria-haspopup="true">${Copy from previous Time Sheet}</button>
I guess the code in bold (tcp...) should be a script include or something like that but cannot find anything like that in my script include list.
Also what makes me really confused is that probably another widget is generated by clicking the button and I have no idea how this could be done via script include.
Appreciate any help on this.
Milan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2020 06:26 AM
Hi,
'tcp.copy.timesheet' is is not a script include, it's just the name of an event. In angular, broadcast is used to send an event to other angular directives/widgets.
In order to listen to a broadcast, you must use angulars $on function.
example
$scope.$on('tcp.copy.timesheet', function(){
//do something
})
More information can be found here

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2020 06:29 AM
I agree with LJ. We were just talking about this live on the community live stream video (link coming) when LJ posted this. Thank you.
You can also send arguments from $root.$broadcast with something like this:
$rootScope.$broadcast('eventName', true);
Then your function has something to use as data when the event is picked up in the other widget.
$rootScope.$on('eventName', function(event,data) {
var myVar = data;
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2020 03:45 AM
Hi Chuck,
In my view we should never use $rootScope.$on but $scope.$on as the earlier would add a new listener every time you navigate back to the page. It would end up in multiple listeners for the same event.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2020 06:31 AM
Hi,
The Code Snippet: $rootScope.$broadcast('tcp.copy.timesheet'); is used to fire an event with the event name as- tcp.copy.timesheet.
So, Go to Registry module of Events and check with the Name passed as argument.
Please Mark my answer correct and helpful if it helps you.
Thanks & Regards,
Prasant kumar sahu