0

I have this ng-repeat:

     <div ng-repeat="prop in props">
<div ng-repeat="tenant in prop.Tenants">
         <label class="col-md-6 control-label">Tenant {{$index?}} ({{tenant.TenantName}})</label>
    </div>
    </div>

I want to have incremented autonumber which will increase by 1 for each tenant in all the property tenants, the array is not important as long as there are tenants from all the arrays the autonumber will increase by 1.

Is there easy way to do this in the html or I need to write some controller code as well?

halfer
  • 19,824
  • 17
  • 99
  • 186
Laziale
  • 7,965
  • 46
  • 146
  • 262
  • You can add this counter in your controller / service, whenever any list of tenants is updated. Just iterate over all props and their tenants and add a field 'id' assigning an incremented number each time. I guess this would be faster than doing any 'math' like this in your view. – Tobi Jan 04 '17 at 14:21
  • I have this in the controller $scope.gradingTenantIncrement = 0; How can I increase by one for each new tenant? Thx – Laziale Jan 04 '17 at 14:22
  • If you want to do it inside the scope, you can have a look at the accepted answer here http://stackoverflow.com/questions/15256600/passing-2-index-values-within-nested-ng-repeat. So you might just want to use '$parent.$index + $index' instead of just $index. – Tobi Jan 04 '17 at 14:23
  • I might need to see more code to get the full picture, but i guess you need to have some code somewhere, where new tenants are added (to any prop). And this is the point i would add the incrementation logic. This could be the success function of an ajax request, asking for additional tenants from a server. – Tobi Jan 04 '17 at 14:24
  • Something like `{{$parent.length + $index}}` would be awesome but... it does not exist yet! :( – Mistalis Jan 04 '17 at 14:51

0 Answers0