Reputation: 733
I´m writing an mobile application with Phonegap,AngularJS and Jquery-Mobile-Adapter.
I like to store data into offline storage as long the application has no connection and send it to a server when the mobile device is online again.
Phonegap offers events for this kind of issues.
Now my question. Whats the best way to integrate the events into AngularJS. How do i sync the data in Background ?
Are there any best practices to combine phonegap and angularjs ?
Regards
Upvotes: 3
Views: 1624
Reputation: 733
I found a nice solution, which works quite well
App.run(function($window, $rootScope, ConnectionService) {
$rootScope.online = ConnectionService.isOnline();
$window.addEventListener("offline", function() {
$rootScope.$apply(function() {
console.log('App is offline');
$rootScope.online = false;
});
}, false);
$window.addEventListener("online", function() {
$rootScope.$apply(function() {
console.log('App is online');
$rootScope.online = true;
});
}, false);
});
But now an other problem appears. Everytime I change the screen orientation the event listener fires
Any ideas
Upvotes: 0
Reputation: 276313
You can use ui-event
directive to handle any events that AngularJS does not provide an event for out of the box:
https://github.com/angular-ui/ui-utils/blob/master/modules/event/event.js
Upvotes: 1