From 60619d511b368a1e55f3545a4cd00e0335f48fe9 Mon Sep 17 00:00:00 2001 From: Tasos Bekos Date: Sat, 29 Jun 2013 12:53:42 +0300 Subject: [PATCH] fix(rating): evaluate `max` attribute on parent scope --- src/rating/docs/demo.html | 3 ++- src/rating/docs/demo.js | 1 + src/rating/rating.js | 2 +- src/rating/test/rating.spec.js | 7 +++++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/rating/docs/demo.html b/src/rating/docs/demo.html index 5182fafdf7..9eb7b7d417 100644 --- a/src/rating/docs/demo.html +++ b/src/rating/docs/demo.html @@ -1,5 +1,6 @@
- + + {{overStar}} / {{max}}
Rate: {{rate}} - Readonly is: {{isReadonly}} - Hovering over: {{overStar || "none"}}
diff --git a/src/rating/docs/demo.js b/src/rating/docs/demo.js index bd69a0be57..428c5956ac 100644 --- a/src/rating/docs/demo.js +++ b/src/rating/docs/demo.js @@ -1,5 +1,6 @@ var RatingDemoCtrl = function ($scope) { $scope.rate = 7; + $scope.max = 10; $scope.isReadonly = false; $scope.hoveringOver = function(value) { $scope.overStar = value; diff --git a/src/rating/rating.js b/src/rating/rating.js index ff3a18d1eb..facef1561c 100644 --- a/src/rating/rating.js +++ b/src/rating/rating.js @@ -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++) { diff --git a/src/rating/test/rating.spec.js b/src/rating/test/rating.spec.js index 9a9e368db4..64b5e2bb48 100644 --- a/src/rating/test/rating.spec.js +++ b/src/rating/test/rating.spec.js @@ -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('')($rootScope); + $rootScope.$digest(); + expect(getStars().length).toBe(15); + }); + it('handles readonly attribute', function() { $rootScope.isReadonly = true; element = $compile('')($rootScope);