Advertisement
Jthami

Untitled

Feb 3rd, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* My controller */
  2.  
  3. .controller('editProfileCtrl', function($scope, $http) {
  4.             // temporarily setting current contact for testing
  5.             $scope.curContact = 2;
  6.             /*
  7.             TO KNOW: using function(data). ng-model="people.name" etc.
  8.             */
  9.  
  10.             // get database info to populate text fields
  11.             $http.get("/*my database URL, this will be changed so it's abstracted*/")
  12.             .success(function(data) {
  13.               $scope.people = data;
  14.           // syntax for referencing:
  15.           //     console.log("name: " + $scope.people[$scope.curContact].name);
  16.  
  17.                 // not sure if I'll use newString yet, but it's here
  18.               var newString = "/*my database URL, this will be changed so it's abstracted*/" + $scope.curContact;
  19.               console.log("newString is: " + newString);
  20.             })
  21.  
  22.             .error(function(data) {
  23.               console.log('server side error occurred.');
  24.             });
  25.  
  26.                   $scope.changeInfo = function(people) {
  27.                       $http.post("/*my database URL, this will be changed so it's abstracted*/", people)
  28.                       .success(function(data) {
  29.  
  30.                       });
  31.  
  32.                    } // end changeInfo
  33.           });
  34.  
  35. /* My html file */
  36.  
  37. <form method="post">
  38.   <div>
  39.   <label for="people.name">Name:</label>
  40.   <input type="text" id="people.name" value="{{people[curContact].name}}"/>
  41.   </div>
  42.  
  43.   <div>
  44.   <label for="people.phone">Phone:</label>
  45.   <input type="text" id="people.phone" value="{{people[curContact].phone}}"/>
  46.   </div>
  47.  
  48.   <div>
  49.   <label for="information.email">Email:</label>
  50.   <input type="email" id="people.email" value="{{people[curContact].email}}"/>
  51.   </div>
  52.  
  53.   <div>
  54.   <label for="information.position">Position:</label>
  55.   <input type="text" id="people.position" value="{{people[curContact].position}}"/>
  56.   </div>
  57.  
  58.   <button ng-click="changeInfo(people[curContact])" type="submit">Save changes</button>
  59. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement