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.

3
  • use ng-repeat directive Commented Mar 1, 2016 at 11:50
  • Concern all questions at stackoverflow , but not get my amswer Commented Mar 1, 2016 at 12:00
  • 1
    Just use ng-repeat like this :stackoverflow.com/questions/16824853/… Commented Mar 1, 2016 at 12:11

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.