Lionel B Lionel B - 20 days ago 4x
Javascript Question

Angular Js - Get a variable in Controller

I have a ladder , my users are order by score and i use a variable in a ng-repeat to know the position of my user in ladder

<tr ng-repeat="user in users| orderBy:'-score'" ng-init="pos=0">
<td>{{pos + $index + 1}}</td>

I want to keep this data in the controller , each user must have a rank

{{pos + $index + 1}}

Example :

{user :
"rank": (result of var {{pos + $index + 1}})

I want to know how to get the result of his value in my controller



In html

{{user.rank = pos + $index + 1}}

above expression assigns result of pos + $index + 1 to user.rank within user object. So, every user object have its own rank kept track seperatly.

In controller you can access each rank using