From 7d662b95608d3757ea65a6a1970cbc5645c3f720 Mon Sep 17 00:00:00 2001 From: praneethkumarpidugu Date: Thu, 7 Jul 2016 23:34:02 -0400 Subject: [PATCH] Updating a contact using our resource --- section6/lesson1/main.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/section6/lesson1/main.js b/section6/lesson1/main.js index 52124bc..098ecbf 100644 --- a/section6/lesson1/main.js +++ b/section6/lesson1/main.js @@ -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) { @@ -56,6 +65,7 @@ app.service('ContactService', function (Contact) { 'page': 1, 'hasMore': true, 'isLoading': false, + 'isSaving': false, 'selectedPerson': null, 'persons': [], 'search': null, @@ -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; + }); } };