2

The following code, will produce the right output, but will crash the angularjs code.

<tr ng-repeat="elnr in elnrs | orderBy: elnr">
    <td>
        <center>{{elnr.elnr}}</center><button ng-click="elnrs.rmElNr({{$index}})" class="btn btn-default" type="button">Remove {{$index}}</button>          
    </td>
</tr>

The fault is in the following code:

ng-click="elnrs.rmElNr({{$index}})"

Where i want, to pass on the index, to an function in my controller, if i hard code the $index with 0 as an example it works fine. The error is as follows:

Error: [$parse:syntax] Syntax Error: Token '$index' is unexpected, expecting [:] at column 16 of the expression [elnrs.rmElNr({{$index}})] starting at [$index}})].

1 Answer 1

4

You don't need to put the {{ }} around the $index in ng-click. Pass it into the ng-click directly and it will recognize it as the index value for the ng-repeat.

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

Comments

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.