I am creating a dynamic table row with an input fields. In angular we can access the index of array by using this $index
variable. Now my problem is I have a sublevels array and I need to get the index of the parent array.
And every row has a remove button. And I need to access the parent index ID for accessing.
Here's the sample object value:
Object
items: Array [2]
0: Object
particular_name: "SAMPLE PARTICULAR TITLE"
child_label: Object
items: Array [3]
0: Object
1: Object
2: Object
$$hashKey: "object:13"
1: Object
particular_name: "SAMPLE PARTICULAR TITLE"
child_label: Object
items: Array [0]
$$hashKey: "object:41"
In my template I have this:
<!-- this is the parent array -->
<div ng-repeat="item in quoteHeader.items" class="row">
<!-- some codes here... -->
<!-- 2nd level array -->
<tr ng-repeat="item in quoteHeader.items[$index].child_label.items">
<!-- need to access the parent index ID here... But index ID here is the index of the 2nd level array-->
<button type="button" class="btn btn-danger" ng-click="removeParent($index)"><span class="fa fa-times"></span></button>
JS:
$scope.removeParent = function($index) {
console.log($index);
//$scope.quoteHeader.items[$index].splice($index, 1);
}