Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(rating): evaluate max attribute on parent scope
Browse files Browse the repository at this point in the history
  • Loading branch information
bekos committed Jun 29, 2013
1 parent 64fff67 commit 60619d5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/rating/docs/demo.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div ng-controller="RatingDemoCtrl">
<rating value="rate" max="10" readonly="isReadonly" on-hover="hoveringOver(value)" on-leave="overStar = null"></rating>
<rating value="rate" max="max" readonly="isReadonly" on-hover="hoveringOver(value)" on-leave="overStar = null"></rating>
<span class="badge badge-inverse" ng-show="overStar && !isReadonly">{{overStar}} / {{max}}</span>

<hr/>
<pre>Rate: <b>{{rate}}</b> - Readonly is: <i>{{isReadonly}}</i> - Hovering over: <b>{{overStar || "none"}}</b></pre>
Expand Down
1 change: 1 addition & 0 deletions src/rating/docs/demo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var RatingDemoCtrl = function ($scope) {
$scope.rate = 7;
$scope.max = 10;
$scope.isReadonly = false;
$scope.hoveringOver = function(value) {
$scope.overStar = value;
Expand Down
2 changes: 1 addition & 1 deletion src/rating/rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ angular.module('ui.bootstrap.rating', [])
replace: true,
link: function(scope, element, attrs) {

var maxRange = angular.isDefined(attrs.max) ? scope.$eval(attrs.max) : ratingConfig.max;
var maxRange = angular.isDefined(attrs.max) ? scope.$parent.$eval(attrs.max) : ratingConfig.max;

scope.range = [];
for (var i = 1; i <= maxRange; i++) {
Expand Down
7 changes: 7 additions & 0 deletions src/rating/test/rating.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ describe('rating directive', function () {
expect(getStars().length).toBe(7);
});

it('shows different number of icons when `max` attribute is from scope variable', function() {
$rootScope.max = 15;
element = $compile('<rating value="rate" max="max"></rating>')($rootScope);
$rootScope.$digest();
expect(getStars().length).toBe(15);
});

it('handles readonly attribute', function() {
$rootScope.isReadonly = true;
element = $compile('<rating value="rate" readonly="isReadonly"></rating>')($rootScope);
Expand Down

0 comments on commit 60619d5

Please sign in to comment.