Skip to content

Instantly share code, notes, and snippets.

@chrisckchang
Created September 29, 2015 01:07
Show Gist options
  • Save chrisckchang/e5e6d7fc59b2b762edec to your computer and use it in GitHub Desktop.
Save chrisckchang/e5e6d7fc59b2b762edec to your computer and use it in GitHub Desktop.
Contact list Angular homepage-specific code
angular.module("contactsApp", ['ngRoute'])
.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl: "list.html",
controller: "ListController",
resolve: {
contacts: function(Contacts) {
return Contacts.getContacts();
}
}
})
})
.service("Contacts", function($http) {
this.getContacts = function() {
return $http.get("/contacts").
then(function(response) {
// XXX - success
return response;
}, function(response) {
alert("Error retrieving contacts.");
});
}
})
.controller("ListController", function(contacts, $scope) {
$scope.contacts = contacts.data;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment