Created
January 18, 2016 21:58
-
-
Save krainet/300b1b3ef1f7396043e6 to your computer and use it in GitHub Desktop.
Products Service Walladog
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
/* | |
* 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