Skip to content

Instantly share code, notes, and snippets.

@wcadap
Created January 1, 2015 13:32
Show Gist options
  • Save wcadap/c38125eb4eb911ed2058 to your computer and use it in GitHub Desktop.
Save wcadap/c38125eb4eb911ed2058 to your computer and use it in GitHub Desktop.
contactApp.factory('contactDataService', ['$http', '$q',
function ($http, $q) {
var _contacts = [];
var _getContacts = function () {
var deferred = $q.defer();
var controllerQuery = "contact/GetContacts";
$http.get(controllerQuery)
.then(function (result) {
// Successful
angular.copy(result.data, _contacts);
deferred.resolve();
},
function (error) {
// Error
deferred.reject();
});
return deferred.promise;
}
//Expose methods and fields through revealing pattern
return {
contacts: _contacts,
getContacts: _getContacts
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment