AngularJS tips and tricks – broadcast online and offline status

Mr. D:

AngularJS tips and tricks – broadcast online and offline status

Originally posted on Terkildsen's Blog:

In continuing my experiments with AngularJS, I often stumble upon new challenges, I haven’t met before. One of these challenges was to broadcast the online and offline status of the browser.

I wanted to be able to hide different parts of the gui, if the user wasn’t online. In order to do that, I had to create a centralized variable, that would notify the gui whenever changes occurred. I did this by applying the following code in my app:

1

As you can see, the function adds an event listener that will…

View original 37 more words