Last active
May 17, 2016 02:13
-
-
Save jimmycann/3790539a708187db69ebc510923f2975 to your computer and use it in GitHub Desktop.
AngularJS Factory - $http get
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
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