Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Bootstrap Rating

I am copying the example from the Angular Bootstrap docs

The HTML(Jade) is :

rating(ng-model="rate" max="max" on-hover="hoveringOver(value)" on-leave="overStar = null") {{rate}}
   span.label(ng-class="{'label-warning': percent<30, 'label-info':percent>=30 && percent<70, 'label-success': percent>=70}", ng-show="overStar && !isReadonly") 
    {{percent}}%
   pre(style="margin:15px 0;")
    | Rate: <b>{{rate}}</b> - Readonly is: <i>{{isReadonly}}</i> - Hovering over: <b>{{overStar || "none"}}

And the javascript:

app.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);
  };

  $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'}
  ];
});

When I click on the element, I get the following error:

Error: [$compile:nonassign] Expression 'undefined' used with directive 'rating' is non-assignable!

Which I understand has something to do with the data binding. Is this a bug in the ui.bootstrap.rating control or am I doing something obviously incorrect ?

like image 227
avrono Avatar asked Jun 25 '26 05:06

avrono


2 Answers

Use value instead of ng-model:

<rating value="rate" max="max"></rating>
like image 109
user3630025 Avatar answered Jun 28 '26 01:06

user3630025


Try including angular bootstrap in your module:

angular.module('myModule', ['ui.bootstrap']);
like image 37
Chancho Avatar answered Jun 28 '26 01:06

Chancho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!