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

Commit

Permalink
feat(progressbar): allow dynamic update to max
Browse files Browse the repository at this point in the history
- Adds ability to dynamically change max value
  • Loading branch information
RaananW authored and wesleycho committed Mar 28, 2015
1 parent f13ed0f commit 7ccff02
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/progressbar/progressbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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($attrs.max) ? $scope.$parent.$eval($attrs.max) : progressConfig.max;
$scope.max = angular.isDefined($scope.max) ? $scope.max : progressConfig.max;

this.addBar = function(bar, element) {
if ( !animate ) {
Expand Down Expand Up @@ -54,6 +54,7 @@ angular.module('ui.bootstrap.progressbar', [])
require: '^progress',
scope: {
value: '=',
max: '=?',
type: '@'
},
templateUrl: 'template/progressbar/bar.html',
Expand All @@ -71,11 +72,12 @@ angular.module('ui.bootstrap.progressbar', [])
controller: 'ProgressController',
scope: {
value: '=',
max: '=?',
type: '@'
},
templateUrl: 'template/progressbar/progressbar.html',
link: function(scope, element, attrs, progressCtrl) {
progressCtrl.addBar(scope, angular.element(element.children()[0]));
}
};
});
});
9 changes: 8 additions & 1 deletion src/progressbar/test/progressbar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ describe('progressbar directive', function () {
it('transcludes "bar" text', function() {
expect(getBar(0).text()).toBe('22/200');
});

it('adjusts the valuemax when it changes', function() {
expect(getBar(0).attr('aria-valuemax')).toBe('200');
$rootScope.max = 300;
$rootScope.$digest();
expect(getBar(0).attr('aria-valuemax')).toBe('300');
});
});

describe('"type" attribute', function () {
Expand Down Expand Up @@ -209,4 +216,4 @@ describe('progressbar directive', function () {
expect(getBar(0)).not.toHaveClass(BAR_CLASS + '-warning');
});
});
});
});

0 comments on commit 7ccff02

Please sign in to comment.