Donthamsetti v bhadrarao Donthamsetti v bhadrarao - 6 months ago 11
AngularJS Question

AngularJS - How to get two indexes

I am having two ng-repeat for child and parent divs as follows

<div ng-repeat="stage in stages">
<div ng-repeat="step in steps">
<button ng-click="clickedStageAndStep($index)">
</div>
</div>

$scope.clickedStageAndStep = function(index) {
console.log("Step Index: " + index)
};


I wanna get child and parent indexes. How can I fetch?

Answer

Use $parent.$index

Each ng-repeat has its own scope and $index refers to innermost scope of ng-repeat

$scope.clickedStageAndStep = function(parent, child) {
  console.log("Step Index: " + child);
};
<div ng-repeat="stage in stages">
  <div ng-repeat="step in steps">
    <button ng-click="clickedStageAndStep($parent.$index,$index)"></button>
  </div>
</div>

Note: </button> tag is not closed.

Comments