Created
May 11, 2015 18:06
-
-
Save alatzl/7347aab0fa4944597539 to your computer and use it in GitHub Desktop.
Utilize Angular's built-in services
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
// 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