Lionel B Lionel B - 1 year ago 78
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


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download