AngularJs broadcast repeating execution too many times

后端 未结 5 1616
北恋
北恋 2020-12-07 17:41

Inside one of my Angular controllers, I have this:

// controller A
$rootScope.$on(\"myEventFire\", function(event, reload) {
    someAction();
});

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 18:14

    if you don't want to destroy,

    I think we can check the listener event first - AngularJS 1.2.15

    So I think this should work :

    if(!$rootScope.$$listenerCount['myEventFire']){
        $rootScope.$on("myEventFire", function(event, reload) {
            someAction();
        });
    }
    

提交回复
热议问题