Skip to content

Instantly share code, notes, and snippets.

@jimmycann
Last active May 17, 2016 02:13
Show Gist options
  • Save jimmycann/3790539a708187db69ebc510923f2975 to your computer and use it in GitHub Desktop.
Save jimmycann/3790539a708187db69ebc510923f2975 to your computer and use it in GitHub Desktop.
AngularJS Factory - $http get
angular.module('app').factory('blogFactory', ['$http',
function ($http) {
//GET all blogs
var get_blogs = function () {
return $http.get('/api/get-blogs')
.then(function(response) {
return response.data; //Flatten the data
});
};
//GET single blog
var get_blog = function (slug) {
return $http.get('/api/blog-item/' + slug)
.then(function(response) {
return response.data;
});
};
return {
get_blogs: get_blogs,
get_blog: get_blog
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment