Created
September 25, 2012 08:03
-
-
Save gonzaloruizdevilla/3780545 to your computer and use it in GitHub Desktop.
AngularJs y detección de conexión para cambiar sistema de almacenamiento
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myApp').run(function($rootScope) { | |
window.addEventListener("online", function () { | |
$rootScope.$broadcast('onlineChanged', true); | |
}, true); | |
window.addEventListener("offline", function () { | |
$rootScope.$broadcast('onlineChanged', false); | |
}, true); | |
}); | |
angular.module('myApp').factory('storage', function($rootScope, $http, LocalStorage) { | |
var currentStorage; | |
$rootScope.$on('onlineChanged', function(evt, isOnline) { | |
if( isOnline ){ | |
synchronizeLocalStorageWithServer(); | |
currentStorage = $http; | |
} else { | |
currentStorage = LocalStorage; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment