Register multiple events with Scope.$on
Be able to bind a listener to multiple events with one call
$scope.$on(['sizeChanged', 'visibilityChanged'], myListener);
The returned deregistration function should remove both of course
PRs: #4492 and #7761
I like this idea $scope.$on(['sizeChanged', 'visibilityChanged'], myListener); I would like to use it. All in one shot. Hope this will be merged in the next version
What about conditionally returning an object containing multiple deregistration functions, keyed by event name?
+1 for $scope.$on(['event1', 'event2', 'event3'], myListener) ... Feel like I would use this all the time.
Seems to fit in nicely with the $q.all(['async1', 'async2', 'async3']) syntax.
+1 I regularly run into places where this functionality would be so useful and make the code much cleaner :)
+1 This is very in-line with other functionality fx. $q.all. It is very useful in bigger projects.
+1
Aside of handling many events with one listener it may also have syntax analogous to Object.defineProperties() where one can define event name(s) for a single handler but also register many handlers at a time.
My case is:
I'm using events to pass simple information about backend request status in my data access object and I want to log them and to inform user if something went wrong.
Now I've written my own function to handle Object.defineProperties()-like syntax but it will be nice to have it just built in
https://gist.github.com/jrencz/f1107bb2432672996dbe
+1
+1
+1
+1
+1
+1
+1
+1 :)
upvote
+1 pls
+1
Just a heads up, looks like this feature request won't be making it into core because "this api is used quite rarely"; https://github.com/angular/angular.js/pull/7761
I could really use this functionality right now... I think you have a ton of people requesting this which makes this use case not so rare..
This is something that can easily be solved with a short helper method, and not something common enough that it makes sense to include in all apps.
When we add a feature like this, it increases the size of Angular for everyone, regardless of whether they need such a feature. I think it's accurate to say that relative to all apps using Angular, this isn't that common of a need.
You can also add this via a 3rd party module with a decorator as described here if you want such a feature: https://github.com/angular/angular.js/pull/7761#issuecomment-54916632
Because there are so many ways to accomplish this without adding bytes to Angular, I really can't justify merging this into core.
Closing.