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

Commit 258b341

Browse files
MartinNucwesleycho
authored andcommitted
fix(progressbar): fix default max value
- Fix logic around falling back to default max value Closes #5374 Fixes #5373
1 parent 81498a7 commit 258b341

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

src/progressbar/progressbar.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ angular.module('ui.bootstrap.progressbar', [])
1010
animate = angular.isDefined($attrs.animate) ? $scope.$parent.$eval($attrs.animate) : progressConfig.animate;
1111

1212
this.bars = [];
13-
$scope.max = angular.isDefined($scope.max) ? $scope.max : progressConfig.max;
13+
$scope.max = getMaxOrDefault();
1414

1515
this.addBar = function(bar, element, attrs) {
1616
if (!animate) {
@@ -19,7 +19,7 @@ angular.module('ui.bootstrap.progressbar', [])
1919

2020
this.bars.push(bar);
2121

22-
bar.max = $scope.max;
22+
bar.max = getMaxOrDefault();
2323
bar.title = attrs && angular.isDefined(attrs.title) ? attrs.title : 'progressbar';
2424

2525
bar.$watch('value', function(value) {
@@ -50,12 +50,17 @@ angular.module('ui.bootstrap.progressbar', [])
5050
});
5151
};
5252

53-
$scope.$watch('max', function(max) {
53+
//$attrs.$observe('maxParam', function(maxParam) {
54+
$scope.$watch('maxParam', function(maxParam) {
5455
self.bars.forEach(function(bar) {
55-
bar.max = $scope.max;
56+
bar.max = getMaxOrDefault();
5657
bar.recalculatePercentage();
5758
});
5859
});
60+
61+
function getMaxOrDefault () {
62+
return angular.isDefined($scope.maxParam) ? $scope.maxParam : progressConfig.max;
63+
}
5964
}])
6065

6166
.directive('uibProgress', function() {
@@ -65,7 +70,7 @@ angular.module('ui.bootstrap.progressbar', [])
6570
controller: 'UibProgressController',
6671
require: 'uibProgress',
6772
scope: {
68-
max: '=?'
73+
maxParam: '=?max'
6974
},
7075
templateUrl: 'uib/template/progressbar/progress.html'
7176
};
@@ -94,7 +99,7 @@ angular.module('ui.bootstrap.progressbar', [])
9499
controller: 'UibProgressController',
95100
scope: {
96101
value: '=',
97-
max: '=?',
102+
maxParam: '=?max',
98103
type: '@'
99104
},
100105
templateUrl: 'uib/template/progressbar/progressbar.html',

src/progressbar/test/progressbar.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,30 @@ describe('progressbar directive', function() {
133133
});
134134
});
135135

136+
describe('"max" attribute using object', function() {
137+
beforeEach(inject(function() {
138+
element = $compile('<uib-progressbar max="settings.max" animate="false" value="settings.value">{{settings.value}}/{{settings.max}}</uib-progressbar>')($rootScope);
139+
$rootScope.$digest();
140+
}));
141+
142+
it('should not modify outside object', function() {
143+
if (typeof $rootScope.settings === 'object') {
144+
// angular set's up the nested object therefore we have to check like this to avoid test crash
145+
expect($rootScope.settings.max).toBeUndefined();
146+
}
147+
expect($rootScope.settings).toBeUndefined();
148+
expect(getBar(0).attr('aria-valuemax')).toBe('100');
149+
$rootScope.settings = {
150+
max: 300,
151+
value: 40
152+
};
153+
$rootScope.$digest();
154+
expect($rootScope.settings.max).toBe(300);
155+
expect(getBar(0).attr('aria-valuemax')).toBe('300');
156+
});
157+
});
158+
159+
136160
describe('"type" attribute', function() {
137161
beforeEach(inject(function() {
138162
$rootScope.type = 'success';

0 commit comments

Comments
 (0)