diff --git a/src/rating/rating.js b/src/rating/rating.js index 55ed9e0d44..10755d6219 100644 --- a/src/rating/rating.js +++ b/src/rating/rating.js @@ -30,7 +30,7 @@ angular.module('ui.bootstrap.rating', []) $scope.rate = function(value) { if ( !$scope.readonly && value >= 0 && value <= $scope.range.length ) { - ngModelCtrl.$setViewValue(value); + ngModelCtrl.$setViewValue(ngModelCtrl.$viewValue === value ? 0 : value); ngModelCtrl.$render(); } }; diff --git a/src/rating/test/rating.spec.js b/src/rating/test/rating.spec.js index 31ef5d2377..2f1135b217 100644 --- a/src/rating/test/rating.spec.js +++ b/src/rating/test/rating.spec.js @@ -55,6 +55,12 @@ describe('rating directive', function () { expect(getState()).toEqual([true, true, true, true, true]); expect($rootScope.rate).toBe(5); expect(element.attr('aria-valuenow')).toBe('5'); + + getStar(5).click(); + $rootScope.$digest(); + expect(getState()).toEqual([false, false, false, false, false]); + expect($rootScope.rate).toBe(0); + expect(element.attr('aria-valuenow')).toBe('0'); }); it('handles correctly the hover event', function() {