Skip to content

Instantly share code, notes, and snippets.

@jlittlejohn
Last active May 1, 2019 15:58
Show Gist options
  • Save jlittlejohn/f543e19d28af5ed0e589 to your computer and use it in GitHub Desktop.
Save jlittlejohn/f543e19d28af5ed0e589 to your computer and use it in GitHub Desktop.
JS: Angular Factory to Get WP Posts
// Credit: Montague Monro
// https://www.youtube.com/watch?v=3WiyGmdOjbc
app.factory('Posts', ['$http', function ($http) {
return {
getPosts: function () {
var response = $http({
url: ajaxurl,
method: "GET",
params: {action: 'test_ajax'}
}).then(function (response) {
return response.data;
});
return response;
}
}
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment