I have the following function in my factory
getSource:function(){
// If not connected to internet
return LocalStorage.getObject("sourcesAll");
// If connected to internet
return SourceRest.getInstance().query().$promise.then(function(data){
LocalStorage.setObject("sourcesAll",data);
return data;
});
}
My SourceRest is just a $resource call
What i want is that if the user is connected to the internet, he downloads the latest data and saves it to his Localstorage and then return it.
If not connected take the data from the Localstorage and return it.
Return data with the promise is working fine
return SourceRest.getInstance().query()
Also returning from the localStorage (if something is saved) is working
return LocalStorage.getObject("sourcesAll");
Can i return my data from the ajax callback or is there another way to do that?