Skip to content

Instantly share code, notes, and snippets.

@dengjonathan
Created October 15, 2016 19:10
angular factory Right way
angular.module('shortly.services', [])
// use of arrow functions seems to break the Angular API
.factory('Links', function($http){
const addOne = url => $http({
method: 'POST',
url: '/api/links',
data: {
url: url
}
});
const getAll = () => $http({
method: 'GET',
url: '/api/links'
})
.then(res => {
return res.data;
});
return {
addOne,
getAll
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment