Reputation: 255
I have object: $scope.formData = {}
How I can delete element in object by $index
:
$scope.formData.university[$index];
I tried:
$scope.formData.university.splice($index);
Upvotes: 2
Views: 2602
Reputation: 2197
You can use 'delete' operator. For more info Refer Link
delete $scope.formData.university[$index];
Upvotes: 1
Reputation: 136154
It should have slice first parameter as $index
& then second one would be 1
$scope.formData.university.splice($index, 1);
Note: using
$index
for deleting element would be risky if you are applying filtering onng-repeat
Instead of that you could add some unique prop in your each element of ng-repeat
you could add id
in it, so that while deleting you could pass that id and then do find index of that element and delete that element from an array like the same way I did wrote above code.
Upvotes: 1