Skip to content

Instantly share code, notes, and snippets.

@krainet
Created January 18, 2016 21:58
Show Gist options
  • Save krainet/300b1b3ef1f7396043e6 to your computer and use it in GitHub Desktop.
Save krainet/300b1b3ef1f7396043e6 to your computer and use it in GitHub Desktop.
Products Service Walladog
/*
* Api Test Módule
*/
angular.module('productsService', [])
.factory('productsService', ['$resource', '$q', '$log',
function ($resource, $q, $log) {
return {
api: function (extra_route) {
if (!extra_route) {
extra_route = '';
}
return $resource(API_URL + '/products/' + extra_route, {}, {
stripTrailingSlashes: false,
query: {
timeout: 15000,
method: 'GET',
isArray: true
},
save: {
timeout: 15000,
method: 'POST'
},
get: {
timeout: 15000,
method: 'GET',
isArray: true
}
});
},
myFunction: function(){
alert('hola');
},
getAction: function () {
//Service action with promise resolve (then)
var def = $q.defer();
this.api().get({}, {}, function (data) {
/*
data.forEach(function(item){
console.log(item);
});
*/
def.resolve(data);
}, function (err) {
def.reject(err);
});
return def.promise;
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment