Last active
June 18, 2017 14:35
-
-
Save kauffmanes/6020bff70b5919f029f9e2ae3e39c757 to your computer and use it in GitHub Desktop.
save function
This file contains 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
//Once connection is detected, submit to server | |
$scope.sync = function () { | |
var records = fetchAll(); | |
//if connection exists | |
if (navigator && navigator.onLine && records.length) { | |
records.forEach(function (find, idx) { | |
//make service call for each record | |
$http({ | |
url: '/api/finds', | |
method: 'POST', | |
data: find | |
}).then(function (res) { | |
//JS date sometime display differently, so toString keeps it more persistent | |
localStorage.removeItem(find.lcKey.toString()); | |
records.splice(idx); //remove from records array | |
}, function (err) { | |
//error handling - service call failures | |
}); | |
}); | |
} else { | |
//error handling - alert user that a connection could not be established | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment