PUBLIC INDEX legacy zcourts.com ZCOURTS - VOL. 02
LONDON - 2026
AngularJS - Communicate between controllers, services and directives
This solution uses JQuery. I already include JQuery in the page so why not use it. If you need a non-JQuery solution here are a few links:
Static article
Imported body
Legacy aliases
Article archive
FIG. 02
notes
surface
research
surface
Article
app model
publish
surface
Imported writing rendered as native Fission Markdown content.
SECTION
Source and context.
The static release keeps the original post body locally while the backend content pipeline is still being built.
legacy
archive
angularjs
events
jquery
pubsub
javascript
Published 2013-01-09 on legacy zcourts.com. Estimated reading time: 2 min.
Original routes are preserved as local aliases so older links keep resolving to this static archive.
This solution uses JQuery. I already include JQuery in the page so why not use it. If you need a non-JQuery solution here are a few links:
StackOverflow suggestions Video tutorial Native AngularJS broadcast
angular.module('fillta.service.Events', ['ngResource'])
    .factory('Events', function () {
        var el = document.createElement('div')
        var EventsListener = {
            on:function (event, callback, unsubscribeOnResponse) {
                $(el).on(event, function () {
                    if (unsubscribeOnResponse) {
                        $(el).off(event, el, callback)
                    }
                    callback.apply(this, arguments) //invoke client callback
                })
            },
            emit:function (event) {
                $(el).trigger(event, arguments)
            }
        }
        return EventsListener;
    })
This is a very quick and dirty entry. Essentially JQuery already has an amazing, cross-browser event system implemented. Its included in the page to make use of a few plugins, it seemed like a better idea to just use it over the other work arounds. And it seems (apparently, not tested myself) the native AngularJS way can be inefficient.
Stick that block of code in your services file. whenever you need to use it in another server or controller just add "Events" as a dependency then you can use, Events.emit('event',arg1,arg2) and in your other controllers subscribe using Events.on('event',function(arg1,arg2){},false) - The third argument is optional, if true then a function is unsubscribed when the event is emitted for the first time, otherwise it stays subscribed and listen for events.
That's it. I have about 30 unpublished posts I need to finish off - Hopefully get the time soon but look forward to some tutorials and info on my experiences working with a range of technologies the last 7+ months (NodeJS,Socket.IO,Cassandra,AngularJS,requireJS,Netty,Higgs and loads more). Hope it is useful.
CR
Courtney Robinson
zcourts.com
Building the infrastructure for the agentic future.
LET'S CONNECT
courtney@crlog.info
Based in London
© 2025 Courtney Robinson. All rights reserved.