Why is the 1 in this index + 1 showing up in my directive?

- 1 answer

Ad

I created a directive with an $index:

HTML:

<tr
     reportrowgroup
     ng-repeat="report in reports | orderBy: sortBy track by $index"
     report="report"
     rowindex="{{$index + 1}}"

JS:

'<td>{{rowindex + 1}}</td>'+

scope: {
  report: '=',
  rowindex: "@"

It works but the result looks like this:

11
21
31

It seems like the 1 is being added in rowindex + 1. How to output the usual 1, 2, 3, etc?

Ad

Answer

Ad

You are passing the correct value to directive using rowindex="{{$index + 1}}". The problem is inside the directive, you should use '{{rowindex}}'. I think this will solve your problem.

Ad
source: stackoverflow.com
Ad