Answer the question
In order to leave comments, you need to log in
How to delete a variable in an array that is in an array?
I'm already banging my head against the wall. Constantly one error, the function is not defined.
Essence:
we have an array, in it under arrays, note:
$scope.gigliList = [{
"gigli": [{
"elemka": "kek"
}, {
"elemka": "kek"
}]
}, {
"gigli": [{
"elemka": "kek"
}, {
"elemka": "kek"
}, {
"elemka": "kek"
}]
}
<section ng-repeat="list in gigliList" ng-init="gigleIndex = $index">
<div ng-repeat="item in list.gigli">...
<factory>
<span ng-click="removeItem(gigleIndex, item, $index)">delete</span>
</factory>
</div>
</section>
$scope.removegigli = function(list) {
var index = $scope.gigliList.indexOf(list); //выбираем нужный
$scope.gigliList.slice(index, 1); // удаляем
}
$scope.removeItem = function(gigleIndex, item, $index) {
// gigleIndex — номер массива родителя
// item сам элемент во втором репеате
// $index номер элемента в репеате.
// и конечно же строчка ниже не работает
$scope.gigleList[rowIndex].slice(item, 1);
Answer the question
In order to leave comments, you need to log in
let's quickly figure it out.
here we have a reference to an object, it does not have a splice method.
Next...
item is redundant here, since we're already passing in the element's index.$scope.gridList[rowIndex].gigli.splice(index, 1)
plnkr.co Post the code.
rowIndex - what is it and where does it come from?
splice() - the index is passed, and you shove the object there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question