title: deleting an angular object from an array - $$hashKey?
body: <p>I have a dialogue that adds a Master Carton to an array of Master Cartons.</p>
  
  <p>A repeater shows 1 or more Master Cartons:</p>
  
  <pre><code>        &lt;div ng-repeat="carton in dimensionsModalVm.masterCartons"&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label class="control-label col-md-3"&gt;Length&lt;/label&gt;
                          &lt;div class="col-md-9"&gt;
                              &lt;input name="length" min="0" max="999" class="form-control input-inline input-xs" type="number" placeholder="Enter Length" ng-model="carton.dimensions.length" required /&gt; inches
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label class="control-label col-md-3"&gt;Weight&lt;/label&gt;
                          &lt;div class="col-md-9"&gt;
                              &lt;input name="weight" min="0" max="999" class="form-control input-inline input-xs" type="number" placeholder="Enter Weight" ng-model="carton.dimensions.weight" required /&gt; pounds
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;button class="btn btn-default" ng-click=" dimensionsModalVm.addMasterCarton()" type="button"&gt;Add another master carton&lt;/button&gt;
  </code></pre>
  
  <p>My creation of the first MC on page init is called </p>
  
  <pre><code>function dimensionsModalInstanceController($http, $uibModal, $uibModalInstance, toastr, cart, masterCarton, CartObservable) {
  
      vm.addMasterCarton = function () {
          vm.masterCartons.push({
              length: 0,
              weight: 0
          });
      };
      vm.addMasterCarton();
  </code></pre>
  
  <p>((
  For what it's worth, dimensionsModalInstanceController is created within the previous modal's controller here - so dimensionsModalInstanceController is dimensionsModalVm:</p>
  
  <pre><code>function masterCartonModalInstanceController($uibModal, $uibModalInstance, cart) {
      vm.yes = function(size) {
          var modalInstance = $uibModal.open({
              templateUrl: 'dimensionsModalContent',
              controller: 'dimensionsModalInstanceController',
              controllerAs: 'dimensionsModalVm',
              ...
  </code></pre>
  
  <p>))</p>
  
  <p>To add another MC, the button simply calls vm.addMasterCarton.</p>
  
  <p>...</p>
  
  <p>Now I want to be able to delete a MC. I've added a [X] in the corner of each MC.</p>
  
  <pre><code>        &lt;div ng-repeat="carton in dimensionsModalVm.masterCartons"&gt;
                  &lt;button class="btn btn-default pull-right" type="button" ng-click="dimensionsModalVm.deleteMasterCarton(this)"&gt;X&lt;/button&gt;
  
      vm.deleteMasterCarton = function (obj) {
          console.log(obj.carton);
          console.log(vm.masterCartons);
      };
  </code></pre>
  
  <p>My output is:</p>
  
  <pre><code>Object {length: 1, weight: 1, $$hashKey: "object:51"}
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Object array
  [
      {
      $$hashKey: "object:33",
          length: 1,
          weight: 1
      },{
  
      $$hashKey: "object:51",
          length: 1,
          weight: 1
      }
  ]
  </code></pre>
  
  <p>How do I tell it to delete the object from the array? I see matching $$hashKeys, but I'm not sure what to do with them.</p>
  
  <p>I don't want to have to invent a unique ID to track them.</p>
  
  <p>If I used <strong>track by index</strong> on my MC repeater, would they get out-of-place as I delete them?</p>
  
  <p>This article:
  <a href="https://stackoverflow.com/questions/15453979/how-do-i-delete-an-item-or-object-from-an-array-using-ng-click">How do I delete an item or object from an array using ng-click?</a></p>
  
  <p>suggests this <em>should</em> work:</p>
  
  <pre><code>         var index = vm.masterCartons.indexOf(obj);
           vm.masterCartons.splice(index, 1);
  </code></pre>
  
  <p>Unfortunately, it does not delete the right one.</p>