Skip to content
This repository has been archived by the owner on Nov 4, 2021. It is now read-only.

Commit

Permalink
Update to use Promise passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewkremer committed Oct 20, 2016
1 parent c13665b commit a80fa91
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions 07-using-apis-with-angular-http/services.js
@@ -1,37 +1,32 @@
angular.module('app.services', [])

.service('Survey', ['$q', '$http', function($q, $http){
.service('Survey', ['$http', function($http){

var api_url = 'YOUR_SHEETSU_URL';
var currentID = 1;

var ret = {
all: function(){
var deferred = $q.defer();

$http.get(api_url).then(function(resp){
return $http.get(api_url).then(function(resp){
if (resp.data.length > 0) currentID = parseInt(resp.data[resp.data.length-1].id);
deferred.resolve(resp.data);
return resp.data;
});

return deferred.promise;
},
},
add: function(data){
var deferred = $q.defer();

currentID++;
data.id = currentID;

$http.post(api_url+'/column/val', data).then(function(resp){
deferred.resolve(resp.data);
return $http.post(api_url, data).then(function(resp){
return resp.data;
});

return deferred.promise;

}
}

ret.all();

return ret;

}]);
}]);

2 comments on commit a80fa91

@OccamsRazorCoder
Copy link

@OccamsRazorCoder OccamsRazorCoder commented on a80fa91 Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish there was a way to flatten this file down and just download the final file.

@david-poindexter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OccamsRazorCoder just click the "View" button, switch to "Raw" view and save it. :)

Please sign in to comment.