How do I create a custom event in an AngularJs service

前端 未结 3 757
孤独总比滥情好
孤独总比滥情好 2020-12-05 00:37

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 inte

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 00:49

    If you want to send an event between services/directives use broadcast:

    $rootScope.$broadcast('buttonPressedEvent');
    

    And recieve it like this:

    $rootScope.$on('buttonPressedEvent', function () {
                 //do stuff
            })
    

提交回复
热议问题