diff --git a/src/rating/rating.js b/src/rating/rating.js index 86327c87a3..c8d726eca2 100644 --- a/src/rating/rating.js +++ b/src/rating/rating.js @@ -37,7 +37,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 038bdd4f39..883f7dda93 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() {