Created
October 15, 2016 19:10
angular factory Right way
This file contains hidden or 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
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