Reputation: 10655
I have a angular array of 5 elements.
$scope.details;
and $scope.details
have these following elements [id, name, points]
.
and now using loop I have added a new element to this $scope.details
for every element.
for(var i = 0; i < $scope.details.length; i++){
$scope.details[i].check = 'f';
}
So, the elements are [id, name, points, check]
;
Now, after performing the logic i need to remove the check from all 5 elements of $scope.details
.
Upvotes: 1
Views: 243
Reputation: 49
We can pass index / id and write delete function in service js file as below:
RemoveFromCart(indexP){
this.items.splice(indexP, 1);
}
Upvotes: 0
Reputation: 22021
Well, your code aren't adding check
property to each element in details
Array. To do it update code to:
for(var i=0; i<$scope.details.length; i++){
$scope.details[i].check = 'f';
}
To remove check element from each item use for loop and delete:
for(var i=0; i<$scope.details.length, i++){
delete $scope.details[i].check
}
In your code snippet you adding check
property to $scope.details
, so you can remove it without for loop:
delete $scope.details.check
Upvotes: 2