0

I have a value {{catadata2.EndorsementList['0'].Rating}}. Value may have 3 or 4 or 5. I want to repeat image <img src="/assets/img/rating.png" /> according to that value. if value is 3 imaged should be display 3 time, if value is 4 image should be display 4 time.

Any possible solution to repeat image using angularJS.

Muhammad Riaz
  • 403
  • 3
  • 8
  • 23

2 Answers2

1

ng-repeat doesn't support counted loops natively; you need to iterate over a collection of some sort.

You can use a technique like in this answer or this answer to implement counted loops with a function that returns a collection, defined in your controller.

In your controller:

$scope.getTimes = function(n) {
  return new Array(n);
};

In your view:

<span ng-repeat="i in getTimes(catadata2.EndorsementList['0'].Rating) track by $index">
  <img src="/assets/img/rating.png">
</span>
Community
  • 1
  • 1
tavnab
  • 2,594
  • 1
  • 19
  • 26
1

Try some think like this:

   <img src="/assets/img/rating.png" ng-repeat="imagenumber in [].constructor(catadata2.EndorsementList['0'].Rating) track by $index" />

You just create here array with length of rating, and repeate arrays lements, with image

alexey
  • 783
  • 1
  • 7
  • 19