I have a code written in JADE that uses two ngRepeat directives, like this:
table
tr(ng-repeat="item in items track by $index")
td: .dropdown
button.btn.btn-default(data-toggle="dropdown") Choose One
ul.dropdown-menu
li(ng-repeat="option in item.options")
// I need this $index's value comes from the first ng-repeat above
a(ng-click="changeOption(item, option, $index)")
Tag <a>
have a ng-click
directive that calls changeOption(item, option, $index)
The problem is that I need $index
from the FIRST ng-repeat
directive in changeOption()
function instead of the second one. Can I change $index
to another name or assign it to another variable so that I can access it in the second iteration?
Thank you
The $index variable is used to get the Index of an item repeated using ng-repeat directive in AngularJS. This article will explain how to use the $index of the row of HTML Table populated using ng-repeat directive in following two scenarios. 1. Get the Index inside the HTML Table cell using AngularJS. 2.
Note: The $index variable is used to get the Index of the Row created by ng-repeat directive. Each row of the HTML Table consists of a Button which has been assigned ng-click directive. The $index variable is passed as parameter to the GetRowIndex function.
The ngRepeat track by $index allows you to specify which items should be repeated using their index number. The ngRepeat is a directive that can be added to the HTML template of an Angular application. It is used for creating lists, and it can take an expression as an argument.
The custom start and end points for ngRepeat also support all other HTML directive syntax flavors provided in AngularJS (such as data-ng-repeat-start, x-ng-repeat-startand ng:repeat-start). Directive Info This directive creates new scope. This directive executes at priority level 1000. This directive can be used as multiElement
No need to use ng-init
, use ng-repeat
's expression support for key/value access. While you're still using an array, they key will be the actual index.
docs - https://docs.angularjs.org/api/ng/directive/ngRepeat
tr(ng-repeat="(t1, category) in vc.listData track by $index"
td: .dropdown
button.btn.btn-default(data-toggle="dropdown") Choose One
ul.dropdown-menu
li(ng-repeat="(t2, option) in item.options")
a(ng-click="changeOption(item, option, t1)")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With