From 204af753398feddd7c49bf1d9e6f4e77bd6edcfe Mon Sep 17 00:00:00 2001 From: praneethkumarpidugu Date: Mon, 11 Jul 2016 22:47:42 -0400 Subject: [PATCH] create a contact using our resource --- section6/lesson1/index.html | 6 +-- section6/lesson1/main.js | 15 +++++- section6/lesson1/templates/form.html | 54 +++++++++++++++++++ .../lesson1/templates/modal.create.tpl.html | 22 ++++++++ 4 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 section6/lesson1/templates/form.html create mode 100644 section6/lesson1/templates/modal.create.tpl.html diff --git a/section6/lesson1/index.html b/section6/lesson1/index.html index 5bffa7b..e3e64f3 100644 --- a/section6/lesson1/index.html +++ b/section6/lesson1/index.html @@ -50,7 +50,7 @@ - + @@ -113,9 +113,9 @@
+ novalidate > - + diff --git a/section6/lesson1/main.js b/section6/lesson1/main.js index 12c6223..d32df45 100644 --- a/section6/lesson1/main.js +++ b/section6/lesson1/main.js @@ -47,7 +47,8 @@ app.controller('PersonListController', function ($scope, $modal, ContactService) $scope.contacts.loadMore(); }; - $scope.showCreateModal = function (){ + $scope.showCreateModal = function () { + $scope.contacts.selectedPerson = {}; $scope.createModal = $modal({ scope: $scope, template: 'templates/modal.create.tpl.html', @@ -55,6 +56,11 @@ app.controller('PersonListController', function ($scope, $modal, ContactService) }) }; + $scope.createContact = function () { + console.log("createcontact"); + $scope.contacts.createContact($scope.contacts.selectedPerson) + }; + $scope.$watch('search', function(newVal, oldVal) { if (angular.isDefined(newVal)) { $scope.contacts.doSearch(newVal); @@ -139,6 +145,13 @@ app.service('ContactService', function (Contact) { self.persons.splice(index, 1); self.selectedPerson = null; }); + }, + 'createContact': function (person) { + self.isSaving = true; + Contact.save(person).$promise.then(function () { + self.isSaving = false; + }); + } }; diff --git a/section6/lesson1/templates/form.html b/section6/lesson1/templates/form.html new file mode 100644 index 0000000..4553703 --- /dev/null +++ b/section6/lesson1/templates/form.html @@ -0,0 +1,54 @@ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
\ No newline at end of file diff --git a/section6/lesson1/templates/modal.create.tpl.html b/section6/lesson1/templates/modal.create.tpl.html new file mode 100644 index 0000000..775b22f --- /dev/null +++ b/section6/lesson1/templates/modal.create.tpl.html @@ -0,0 +1,22 @@ + \ No newline at end of file