Within my $scope, there is a property called $scope.cars
, which is an array of cars. Users have the ability to delete a car from this array. When calling the delete function deleteThis
, I pass the $index parameter created by ng-repeat. However, in the JavaScript function that receives this parameter, I am unsure how to use it to locate and remove the corresponding car from $scope.cars. Since $index is not a built-in part of $scope.cars, I am seeking guidance on how to achieve this.
$scope.deleteThis = function($event, $index){
// How can I utilize $index to find the car in $scope.cars and delete it?
}
<div ng-repeat="car in cars">
<div class="row">
<div class="col-md-1"><h2>{{car.name}}</h2>{{car.make}}</div>
<div class="col-md-2"></div>
<span class="delete" ng-click="deleteThis($event, $index)">x</span>
</div>