1

I have a button code block in jsp below which will pass $index of a selected checkbox to a javascript function in controller js which is defined on $scope. But when i try to print the $index on console i am getting undefined value for $index.

Code in Jsp

<button type="button" class="btn btn-warning"
                        ng-disabled='validCheckbox'
                        **ng-click="addTemplate($index)">**
                        <i class="glyphicon glyphicon-plus"></i>&nbsp;Add Middle
     </button>

Code in Js.

 $scope.addTemplate = function(index){
         console.log("index"+index);
1
  • $index is a special property of the ngRepeat scope. If you're not inside an ngRepeat, there's no $index. Commented Jun 21, 2021 at 15:33

1 Answer 1

0

You can use $index only in ng-repeat in angular.js. Here is an example of how to use $index. Let say you have StringArray=['a','b','c'];

<div ng-repeat="c in StringArray">
      <label>{{$index}}</label>
</div>

The result is :0, 1, 2

Sign up to request clarification or add additional context in comments.

1 Comment

Does this answer your question, check the link below? stackoverflow.com/questions/24873335/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.