3

I am able to get the a number from the database and display it in .html as

<tr ng-repeat="review in reviews ">
          <td>{{review.reviewer}}</td>
          <td>{{review.comment}}</td>
          <td>{{review.rating}}</td>

here, {{review.rating}} is a given number.

How could I use Bootstrap to display the star rating for the given number?

thegio
  • 1,233
  • 7
  • 27
Freedom Gu
  • 61
  • 1
  • 2

1 Answers1

7

you can use the Angularjs Bootstrap UI directive:

https://angular-ui.github.io/bootstrap/

-> Rating (ui.bootstrap.rating)

example: http://plnkr.co/edit/wpfxg0zqSLHPtQVBHdGi?p=preview

index.html

<div ng-controller="RatingDemoCtrl">
    <h4>Rating</h4>
    <uib-rating ng-model="rate" max="max" read-only="isReadonly" on-hover="hoveringOver(value)" on-leave="overStar = null" titles="['one','two','three']" aria-labelledby="default-rating"></uib-rating>
        <span class="label" ng-class="{'label-warning': percent<30, 'label-info': percent>=30 && percent<70, 'label-success': percent>=70}" ng-show="overStar && !isReadonly">{{percent}}%</span>
</div>

app.js

angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('RatingDemoCtrl', function ($scope) {
  $scope.rate = 7;
  $scope.max = 10;
  $scope.isReadonly = false;

  $scope.hoveringOver = function(value) {
    $scope.overStar = value;
    $scope.percent = 100 * (value / $scope.max);
  };

});
thegio
  • 1,233
  • 7
  • 27