How to use $rootScope.$on to register a listener?

45 views
Skip to first unread message

Siyuan Wang

unread,
Mar 11, 2014, 12:40:43 PM3/11/14
to ang...@googlegroups.com
I have looked through the api doc from Dash of my mac, the doc only shows that 
The event listener function format is: function(event, args...)
which doesn't explain what the "args" is!  That means nothing for me. 
Where can I find the exact format of the listener function?

Kamal

unread,
Mar 11, 2014, 1:11:02 PM3/11/14
to ang...@googlegroups.com
Siyuan,

"args" are the arguments which are passed to the $emit/$broadcast methods which invoke the methods registered using the $on. Let's see an example

$scope.$emit('myevent', "First Name", "Last Name", 3, "Test"); -> To Emit

$scope.$on('myevent', function(event, fname, lname, role, extra) {
  // fname -> "First Name"
  // lname -> "Last Name"
  // role -> 3
  // extra -> "Test"
});

this can be either $rootScope or any scope.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages