Business scenario description:
Assume that in the child controller, the user's various click operations will be divided into two events, which will be broadcast to the parent controller by the controller
$scope.$emit('ngUserLogin');
$scope.$emit('ngUserUpdate');
In the parent controller, we use $on to listen to these two events, yes,
$scope.$on('ngUserlogin', function(){"}
$scope.$on('ngUserUpload', function(){"}
But in a certain scene, I found that these two events executed the same logic, so I wanted to write it like this:
$scope.$on(['ngUserlogin','ngUserUpload'], function(){"}
This is the mode I expected, but ng obviously cannot be written like this. I would like to ask you how to monitor more than two events at the same time in your actual business
It’s a pity that
ng
does not have the mode you expected. To make a little trick, you can write like this:You can change your thinking, you only send one event, and then bring different parameters when sending this event
$emit(name, args);
; when you listen to this event, judge the parameters, and you will know what you want to do next.