title: Angular: Keep model data in sync with database
body: <p>i'm making my first weapons with Angular. I cannot understand the best way to handle data modifications in model and store it in the database, e.g:</p>
  
  <p>In controller:</p>
  
  <pre><code>$scope.items = [
      { id: 1, status: 0, data: 'Foo Item' }
      { id: 2, status: 0, data: 'Foooo' }
      { id: 3, status: 1, data: 'OooItem' }
  ];
  </code></pre>
  
  <p>In view:</p>
  
  <pre><code>    &lt;tr ng-repeat="item in items | orderBy:'-id'"&gt;
          &lt;td&gt;{{item.id}}&lt;/td&gt;
          &lt;td&gt;{{item.data}}&lt;/td&gt;
          &lt;td&gt;
              &lt;div class="btn-group" role="group"&gt;
                  &lt;button type="button" class="btn btn-default" ng-click="status(item.id, 1)"&gt;Acept&lt;/button&gt;
                  &lt;button type="button" class="btn btn-default" ng-click="status(item.id, 2)"&gt;Reject&lt;/button&gt;
              &lt;/div&gt;                    
          &lt;/td&gt;
      &lt;/tr&gt;
  </code></pre>
  
  <p>What should I do to update the item status to 1 or 2? Make a call to the server, and then retrieve the new model? Update the model data with JS, and make the call? Is any way to do it automatic? Angular provide some method to access to the current "clicked" item to update the prop (status in this case)?</p>
  
  <p>Hope I was clear.
  Thanks.</p>
  
  <p><strong>EDIT:</strong> So, based on Dr Jones comment, i write this using underscore.</p>
  
  <pre><code>function status(id, status) {
      $http.put().then()....
      //after success response, update the model
      item = _.find($scope.items, function (rw) {
          return rw.id == id
      });
  
      item.status = status;
  }
  </code></pre>
  
  <p>This is a valid and correct way to this?</p>