Skip to content

Instantly share code, notes, and snippets.

@sivaprasadreddy
Created September 5, 2014 12:15
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 sivaprasadreddy/8a1744e0696fbdaa9375 to your computer and use it in GitHub Desktop.
Save sivaprasadreddy/8a1744e0696fbdaa9375 to your computer and use it in GitHub Desktop.
Contact-Service-Ctrl.js
myApp.service('ContactService', ['$http',function($http){
this.getContacts = function(){
var promise = $http.get('contacts')
.then(function(response){
return response.data;
},function(response){
alert('error');
});
return promise;
}
}
}]);
myApp.controller('ContactController', [ '$scope', 'ContactService', function ($scope, ContactService) {
ContactService.getContacts().then(function(data) {
$scope.contacts = data;
});
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment