diff --git a/src/progressbar/progressbar.js b/src/progressbar/progressbar.js index 8e983c6c3c..77f103b881 100644 --- a/src/progressbar/progressbar.js +++ b/src/progressbar/progressbar.js @@ -10,7 +10,7 @@ angular.module('ui.bootstrap.progressbar', []) animate = angular.isDefined($attrs.animate) ? $scope.$parent.$eval($attrs.animate) : progressConfig.animate; this.bars = []; - $scope.max = angular.isDefined($scope.max) ? $scope.max : progressConfig.max; + $scope.max = getMaxOrDefault(); this.addBar = function(bar, element, attrs) { if (!animate) { @@ -19,7 +19,7 @@ angular.module('ui.bootstrap.progressbar', []) this.bars.push(bar); - bar.max = $scope.max; + bar.max = getMaxOrDefault(); bar.title = attrs && angular.isDefined(attrs.title) ? attrs.title : 'progressbar'; bar.$watch('value', function(value) { @@ -50,12 +50,17 @@ angular.module('ui.bootstrap.progressbar', []) }); }; - $scope.$watch('max', function(max) { + //$attrs.$observe('maxParam', function(maxParam) { + $scope.$watch('maxParam', function(maxParam) { self.bars.forEach(function(bar) { - bar.max = $scope.max; + bar.max = getMaxOrDefault(); bar.recalculatePercentage(); }); }); + + function getMaxOrDefault () { + return angular.isDefined($scope.maxParam) ? $scope.maxParam : progressConfig.max; + } }]) .directive('uibProgress', function() { @@ -65,7 +70,7 @@ angular.module('ui.bootstrap.progressbar', []) controller: 'UibProgressController', require: 'uibProgress', scope: { - max: '=?' + maxParam: '=?max' }, templateUrl: 'uib/template/progressbar/progress.html' }; @@ -94,7 +99,7 @@ angular.module('ui.bootstrap.progressbar', []) controller: 'UibProgressController', scope: { value: '=', - max: '=?', + maxParam: '=?max', type: '@' }, templateUrl: 'uib/template/progressbar/progressbar.html', diff --git a/src/progressbar/test/progressbar.spec.js b/src/progressbar/test/progressbar.spec.js index 16ae8212e6..e7fa4a8500 100644 --- a/src/progressbar/test/progressbar.spec.js +++ b/src/progressbar/test/progressbar.spec.js @@ -133,6 +133,30 @@ describe('progressbar directive', function() { }); }); + describe('"max" attribute using object', function() { + beforeEach(inject(function() { + element = $compile('{{settings.value}}/{{settings.max}}')($rootScope); + $rootScope.$digest(); + })); + + it('should not modify outside object', function() { + if (typeof $rootScope.settings === 'object') { + // angular set's up the nested object therefore we have to check like this to avoid test crash + expect($rootScope.settings.max).toBeUndefined(); + } + expect($rootScope.settings).toBeUndefined(); + expect(getBar(0).attr('aria-valuemax')).toBe('100'); + $rootScope.settings = { + max: 300, + value: 40 + }; + $rootScope.$digest(); + expect($rootScope.settings.max).toBe(300); + expect(getBar(0).attr('aria-valuemax')).toBe('300'); + }); + }); + + describe('"type" attribute', function() { beforeEach(inject(function() { $rootScope.type = 'success';