$digest-free Event Aggregator for AngularJS inspired by Backbone's event aggregator.
Include angular-event-aggregator.js
after your main AngularJS script.
Specify ngEventAggregator
as a dependency for your Angular application:
var app = angular.module('myApp', ['ngEventAggregator']);
Now you can inject eventAggregator
anywhere in your application, and register a listener.
app.controller("MyCtrl", ['eventAggregator', function(eventAggregator){
var myCallback = function(item) {
console.log(item);
eventAggregator.off('some.event.happens', myCallBack);
};
eventAggregator.on('some.event.happens', myCallBack);
}]);
or execute a trigger.
app.controller("SomeOtherCtrl", ['eventAggregator', function(eventAggregator){
eventAggregator.trigger('some.event.happens', {data: 'payload'});
}]);
In order to run the unit tests, run bower install
to get angular dependencies and npm install
to get karma and related dependecies.
Run npm test
to run the test suite.