AngularJS $broadcast With Multiple Parameters


Answer :

Just put the parameters into an object:

$scope.$broadcast('event', { a: item1, b: item2 }) 

Then access them from the second argument to the callback:

$scope.$on('event', function(event, opt) {  // access opt.a, opt.b }); 

Or if using ES2015 syntax you can unpack the arguments:

$scope.$on('event', (event, {a,b}) => {  // access them just as a, b }); 

Documentation says:

'Optional one or more arguments which will be passed onto the event listeners'

$rootScope.$emit(event_name, p1, p2, p3);


Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?