Skip to content

Commit 6797e05

Browse files
committed
Watch max attribute
1 parent e62ab94 commit 6797e05

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/progressbar/progressbar.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@ 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($attrs.max) ? $scope.$parent.$eval($attrs.max) : progressConfig.max;
13+
14+
this.updateBar = function(bar) {
15+
bar.percent = +(100 * bar.value / $scope.max).toFixed(2);
16+
}
17+
18+
if (angular.isDefined($attrs.max)) {
19+
$scope.$parent.$watch($attrs.max, function (new_value) {
20+
$scope.max = new_value;
21+
for (i=0; i<self.bars.length; i++) {
22+
self.updateBar(self.bars[i]);
23+
}
24+
});
25+
} else {
26+
$scope.max = progressConfig.max;
27+
}
1428

1529
this.addBar = function(bar, element) {
1630
if ( !animate ) {
@@ -20,7 +34,8 @@ angular.module('ui.bootstrap.progressbar', [])
2034
this.bars.push(bar);
2135

2236
bar.$watch('value', function( value ) {
23-
bar.percent = +(100 * value / $scope.max).toFixed(2);
37+
bar.value = value;
38+
self.updateBar(bar);
2439
});
2540

2641
bar.$on('$destroy', function() {

0 commit comments

Comments
 (0)