user1897580
user1897580

Reputation: 1

ng-repeat is repeating multiple time with same array

ng-repeat is binding same array with multiple times.

js :

    $scope.currentitem = item;
    $scope.currentitemCategory = $scope.currentitem.category.split(',');
    console.log($scope.currentitemCategory);

html:

   <div ng-repeat="category in currentitemCategory track by $index">
             <a href="/content/digital-library/us/en/search.html?category={{category}}">
            <span class="text"> {{category}} </span>
            </a>
                                         </div>

console :

Categorized in audience/business audience/business audience/business brandguidelines brandguidelines brandguidelines corporateinitiatives/idf corporateinitiatives/idf corporateinitiatives/idf

Upvotes: 0

Views: 458

Answers (1)

Nikhilesh Shivarathri
Nikhilesh Shivarathri

Reputation: 1670

I've created a sample application with your given snippet. I do not see any repeated entries. Everything works fine. Please provide few more details if the issue really exists.

var app= angular.module('sample', []);

app.controller('samplecontroller', function($scope){
   var item = {category: 'Tennis, Carroms, Soccer, Volleyball'};
   $scope.currentitem = item;
   $scope.currentitemCategory = $scope.currentitem.category.split(',');
   console.log($scope.currentitemCategory);
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body ng-app="sample">
  <div ng-controller="samplecontroller">
    <div ng-repeat="category in currentitemCategory track by $index">
      <a href="/content/digital-library/us/en/search.html?category={{category}}">
        <span class="text"> {{category}} </span>
      </a>
    </div>
  </div>

</body>

Upvotes: 1

Related Questions