Skip to content

Instantly share code, notes, and snippets.

@alatzl
Created May 11, 2015 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alatzl/7347aab0fa4944597539 to your computer and use it in GitHub Desktop.
Save alatzl/7347aab0fa4944597539 to your computer and use it in GitHub Desktop.
Utilize Angular's built-in services
// Instead of using $.ajax for an API call...
angular.module('app', [])
.factory('addressBook', function() {
var data = null;
return {
getAddresses: function() {
$.ajax({
url: '/path/to/data',
dataType: 'json',
success: function(result) {
data = result;
},
error: function(error) {}
});
}
};
});
// Try using Angular's $http service
angular.module('app')
.factory('addressBook', function($http){
return {
getAddresses: function() {
return $http({
method: 'GET',
url: '/path/to/data'
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment