Hi there,
I am building an application for my masters thesis which should be able to work online and offline.
The idea is that the application fetches the data either from a remote server (when online) or the browsers local storage (when offline).
I have two questions concerning this idea:
1.)
My approach is to create a proxy service which uses either the $http service or a custom LocalStorage service depending on the navigator.onLine property.
I created a very basic fiddle to demonstrate my approach:
http://jsfiddle.net/rommsen/DqKtx/9/ Is there any better or "more angular" way of doing this? I was thinking of implementing the LocalStorage service similar to the $http service but to be honest I can not really get a grip of the $q and defer api.
2.)
The application needs to listen (globally) to changes of its online/offline state. Something like:
window.addEventListener("online", function () {
alert("You're now online");
}, true);
window.addEventListener("offline", function () {
alert("You're now offline.");
}, true);
I am still not 100% into the angular way of doing things. Where should I put these event listeners and what is the best way of implementing them.
Thanks a lot,
Roman