Skip to content

Commit

Permalink
Updating a contact using our resource
Browse files Browse the repository at this point in the history
  • Loading branch information
praneethkumarpidugu committed Jul 8, 2016
1 parent 842c9f0 commit 7d662b9
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion section6/lesson1/main.js
Expand Up @@ -16,11 +16,20 @@ app.config(function ($httpProvider, $resourceProvider, laddaProvider) {
});
});
app.factory('Contact', function ($resource) {
return $resource("http://codecraftpro.com/api/samples/v1/contact/:id/");
return $resource("http://codecraftpro.com/api/samples/v1/contact/:id/", {id:'@id'}, {
update: {
method: 'PUT'
}
});
});

app.controller('PersonDetailController', function ($scope, ContactService) {
$scope.contacts = ContactService;

$scope.save = function () {
$scope.contacts.updateContact($scope.contacts.selectedPerson)

}
});

app.controller('PersonListController', function ($scope, ContactService) {
Expand Down Expand Up @@ -56,6 +65,7 @@ app.service('ContactService', function (Contact) {
'page': 1,
'hasMore': true,
'isLoading': false,
'isSaving': false,
'selectedPerson': null,
'persons': [],
'search': null,
Expand Down Expand Up @@ -100,6 +110,13 @@ app.service('ContactService', function (Contact) {
self.page += 1;
self.loadContacts();
}
},
'updateContact': function (person) {
console.log("Service Called Update");
self.isSaving = true;
person.$update().then(function () {
self.isSaving = false;
});
}

};
Expand Down

0 comments on commit 7d662b9

Please sign in to comment.