title: AngularJS : Binding ngrepeat values to model in AngularJS
body: <p>I am creating a simple FHIR client to edit patient data using AngularJS. I can't figure out why the values in the inputs are not bound to values in the object.</p>
  
  <p>Naturally, I could cheat and implement <code>keyup</code> and <code>$scope.$apply()</code>, but something tells me this is not how it is supposed to be done in AngularJS.</p>
  
  <p>I've tried using <code>$index</code> to bind the values directly to the values in the array, but that didn't seem to do anything.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>var app = angular.module('FhirClient', []);
  app.controller('PatientCtrl', function ($scope, $http) {
  
  console.log("Evaluating Patient");
  var responsePromise = $http.get("http://nprogram.azurewebsites.net/Patient/1?_format=json&amp;_sm_au_=iMH046nNq52RDM6q");
  
  responsePromise.success(function (data, status, headers, config) {
      console.log("Successful connection");
      $scope.patient = data;
  });
  responsePromise.error(function (data, status, headers, config) {
      alert("AJAX failed!");
  });
  
  $scope.$watch('patient', function (newValue, oldValue) {
      console.log(newValue);
  });
  
  });
  </code></pre>
  
  <p>And the following HTML:</p>
  
  <pre><code>&lt;div ng-controller="PatientCtrl"&gt;
      &lt;div class="container"&gt;
          &lt;h1&gt;Patient Details&lt;/h1&gt;
  
          &lt;code&gt;{{patient | json}}&lt;/code&gt;
          &lt;div class="col-md-6"&gt;
              &lt;h2&gt;Names&lt;/h2&gt;
              &lt;div class="list-group" ng-repeat="names in patient.name track by $namesIndex"&gt;
                  &lt;h3&gt;&lt;span class="label label-primary"&gt;{{x.use}}&lt;/span&gt;&lt;/h3&gt;
                  &lt;div class="form-group" ng-repeat="lastName in names.family track by $familyNamesIndex"&gt;
                      &lt;label for="familyName"&gt;Family Names:&lt;/label&gt;
                      &lt;input class="form-control" ng-model="lastName" /&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group" ng-repeat="firstName in names.given"&gt;
                      &lt;label for="givenName"&gt;Given Names:&lt;/label&gt;
                      &lt;input class="form-control" type="text" ng-model="firstName"/&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="col-md-6"&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and the JSON:</p>
  
  <pre><code>{
  "resourceType":"Patient",
      "text":
      {
          "status": "generated",
          "div": "&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;p&gt;Harley N Hobbs&lt;/p&gt;&lt;p&gt;16 Pier Road&lt;/p&gt;&lt;p&gt;STANWARDINE IN THE FIELDS&lt;/p&gt;&lt;p&gt;SY4 7IW&lt;/p&gt;&lt;p&gt;Date of birth: 1966-06-07&lt;/p&gt;&lt;/div&gt;"
      },
      "identifier":
      [{
          "use": "official",
          "label": "SSN",
          "system": "http://hl7.org/fhir/sid/us-ssn",
          "value": "1"
      }],
      "name":
      [{
          "use": "official",
          "family":[ "Hobbs"],
          "given":[ "Harley"]
      }],
      "telecom":
      [{
          "system": "phone",
          "value": "077 8169 8899",
          "use": "home"
      }],
      "gender":
      {
          "coding":
          [{
              "system": "http://hl7.org/fhir/sid/v2-0001",
              "code": "male"
          }]
      },
      "birthDate": "1966-06-07",
      "deceasedBoolean": false,
      "address":
      [{
          "use": "home",
          "text": "16 Pier Road, STANWARDINE IN THE FIELDS, SY4 7IW",
          "line":[ "16 Pier Road"],
          "city": "STANWARDINE IN THE FIELDS",
          "zip": "SY4 7IW"
      }],
      "careProvider":
      [{
          "reference": "../organization/@1"
      }],
      "active": true
  
  }
  </code></pre>
  
  <p>Any thoughts on what I am doing wrong here?</p>
  
  <p>Here is a simplified JSFiddle: <a href="https://jsfiddle.net/gmpp2fyk/1/" rel="nofollow">https://jsfiddle.net/gmpp2fyk/1/</a> . If you edit the textbox, JSON doesn't seem to be updated: <code>$watch</code> doesn't fire and the expression remains just the way it was.</p>