A communication service to allow easy passing and listening of events (with optionaldata) around an angular application. Events are broadcast from the $rootScope, making it easy to listen to events from anywhere in your application.
There are two easy ways to install the checkie directive:
To install via Bower, run:
coms.service.js file, and include it in your index.html file with something like:
Also be sure to include the module in your app.js file with:
Sending signals (events)
Sending events are as easy as calling the
sendSignal method. You pass the event string to be sent as the first parameter, and any data you wish to pass with the event as the second.
Sometimes with the async nature of AngularJS, you need to delay the sending of a call until something else is ready. This can be done as follows, in this case, delaying the sending of the event by 400ms:
Listening for signals (events)
To listen for an event, you can use the onSignal method, which takes a signal string as the first parameter, a function to listen to the event and a scope to automatically remove the listener if the scope is destroyed (handy for controlling memory leaks).
Deregistering event listeners
Like native angular events, the
onSignal method returns the de-registering function as part of the call. You can assign this to a variable and call it later to manually remove a listener. Listeners are de-registed automatically when the scope is destroyed as long as you pass the scope as the last parameter of the listener.