I am working on an AngularJs project. I have a service which sets and removes events on some buttons. This service is utilized by another service which I do not want to interact directly with the buttons. However I would like a button click event to be filtered up through the first service and handled in the second one. Since I don't want the second service to be aware of the buttons, I figure I will need to create a custom event in the first service. How can I create a custom event and fire it when a button is clicked?
Thanks in advance.
If you want to send an event between services/directives use broadcast:
broadcast
$rootScope.$broadcast('buttonPressedEvent');
And recieve it like this:
$rootScope.$on('buttonPressedEvent', function () { //do stuff })
1.4m articles
1.4m replys
5 comments
57.0k users