1
 <table class="table table-bordered">
      <tr ng-repeat="x in AppliedJob">
    <td>{{x.JobName}}</td>
 <td>  <span class="dropdown" ng-repeat="y in AppliedCenter|  unique: 'Location' " ng-if="y.JobName==x.JobName">
 {{$index+1}}){{y.Location}}                      
 </span> </td></tr> </table>

Output of above code

1) Tester    :  1)India 2)USA 3)Australia
2) Developer :  4)Japan 5)China

Required Output

1) Tester    :  1)India 2)USA 3)Australia
2) Developer :  1)Japan 2)China

I want to set $Index to 1.

J. Chomel
  • 8,193
  • 15
  • 41
  • 69
  • why you do not try with local variable intialize in html page using ng-init and try to intialize outer loop looping at every time intialize with 1. – VjyV Aug 31 '16 at 05:53

1 Answers1

0

It happens because you're filtering using ng-if which is not affect array and it's indexes, it just removes the element from DOM. You should use filter instead of y.JobName==x.JobName comparison in ng-if so yours ng-repeat expression should be like this y in AppliedCenter | unique: 'Location' | filter: { JobName: x.JobName }. See example:

angular
.module('Test', [])
.controller('TestController', ['$scope', function($scope) {
  $scope.cities = ["New York", "LA"];
  $scope.jobs = [{ name: "QA", city: "New York"}, { name: "Frontend", city: "New York"}, {name: "Backend", city: "New York"}, {name: "DBA", city: "LA"}, { name: "QA", city: "LA"}];
  }]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<div ng-app="Test">
  <div ng-controller="TestController">
    <table>
      <tr ng-repeat="city in cities">
        <td ng-bind="city"></td>
        <td>
          <span ng-repeat="job in jobs | filter:{city: city}">{{($index + 1) + ")" + job.name}} </span>
        </td>
      </tr>
     </table>
  </div>
</div>
G07cha
  • 4,009
  • 2
  • 22
  • 39
  • $index work but in json duplicate entry/value so when i use ng-if it shows only one but in filter its show all then how it distinct ex. like see LA 1)DBA 2)DBA 3)QA 4)QA –  Aug 31 '16 at 06:53
  • You should combine `filter` with `unique` and it will remove dublicates. – G07cha Aug 31 '16 at 07:02