AngularJS, code.explode, Coding

Hailing All Frequencies – Communicating in AngularJS with the Pub/Sub Design Pattern

Hailing All Frequencies! Is anybody out there? This is the USS AngularJS, we have a problem our services are speaking in Klingon and our controllers can’t communicate with their Ferengi directives. Can anyone help us!

I don’t know how many times I’ve seen a question about what is the best way to communicate between components in AngularJS. A lot of the time the resulting answer is to use the $rootScope object to $broadcast a message to anyone who might be listening for it. But, that really isn’t the best way to do it. Broadcasting messages between components means that they need to know too much about how things are coded reducing their modularity and re-use.

In this article I show you how to use the Pub/Sub Design Pattern for inter-component communications in AngularJS.

Continue reading

Standard