title: How can I replace an object in array that is displayed using ng-repeat?
body: <p>I have an array of items that is displayed in a table using ng-repeat. When you click on an item, that item is pulled from the server and the table should then be updated with the updated item.</p>
  
  <p>Function to get the updated item when clicking on an item in the table:</p>
  
  <pre><code>$scope.getUpdatedItem = function(item){
      itemService.getItem(item).then(
          function(updatedItem){
              item = updatedItem;
          },
          function(error){
              //Handle error
          }
      );
  };
  </code></pre>
  
  <p>I'm displaying the items using:</p>
  
  <pre><code>&lt;tr ng-repeat="item in myItems"&gt;
  </code></pre>
  
  <p>The problem: The item in the table is never updated.</p>
  
  <p>What's the best way to update the item in the ng-repeat? Can i use "track by $index" in the ng-repeat for this? Or do I have to iterate over myItems to find the item I want to replace?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>A possible solution is instead of using </p>
  
  <p><code>item = updatedItem,</code></p>
  
  <p>to use:</p>
  
  <pre><code>var index = $scope.myItems.indexOf(item);
  $scope.myItems[index] = updateItem;
  </code></pre>
  
  <p>However, I feel that there should be a "cleaner" way of doing this.</p>