0

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

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

  $scope.ratingStates = [
    {stateOn: 'glyphicon-ok-sign', stateOff: 'glyphicon-ok-circle'},
    {stateOn: 'glyphicon-star', stateOff: 'glyphicon-star-empty'},
    {stateOn: 'glyphicon-heart', stateOff: 'glyphicon-ban-circle'},
    {stateOn: 'glyphicon-heart'},
    {stateOff: 'glyphicon-off'}
  ];
});
<!doctype html>
<html ng-app="ui.bootstrap.demo">
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-animate.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-sanitize.js"></script>
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js"></script>
    <script src="example.js"></script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>

<div ng-controller="RatingDemoCtrl">
    <h4>Default</h4>
    <span 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"></span>
    <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>

    <pre style="margin:15px 0;">Rate: <b>{{rate}}</b> - Readonly is: <i>{{isReadonly}}</i> - Hovering over: <b>{{overStar || "none"}}</b></pre>

    

    
</div>
  </body>
</html>

Hi all, I have the above uib star raing code snippet. Here, I want to achieve average star rating which is required for my project. Can anyone help me out with a solution to this?

  • average of what? You seem to have only one rating bar here.. – tanmay May 16 '17 at 09:56
  • Question is not clear. can you add more details? – Praveen M P May 16 '17 at 09:59
  • @Sinchan in that case you should `Math.round()` or `ceil/floor` your rating as per requirements – tanmay May 16 '17 at 10:18
  • 1
    @Sinchan I don't think that's possible using `uib-rating` – tanmay May 17 '17 at 07:24
  • okay. any other alternative using angularjs? –  May 17 '17 at 11:19
  • @Sinchan this is bit old post, but did you check https://stackoverflow.com/questions/30956488/create-a-decimal-star-rating-for-a-comment-in-angularjs post, as it has an alternate to this. I was too looking for displaying decimal point start rating and I assume you too are looking for the same. I haven't yet verified ui.bootstrap as I thought it would have this ability. – Jit Jun 29 '17 at 00:15
  • It's don elong back –  Jun 29 '17 at 05:34

0 Answers0