Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/global/percentage/percentage.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function PercentageMaskDirective($locale, $parse, PreFormatters, NumberMasks) {
}

var valueToFormat = preparePercentageToFormatter(value, decimals, modelValue.multiplier);
return viewMask.apply(valueToFormat) + ' %';
return viewMask.apply(valueToFormat) + (hideSpace ? '%' : ' %');
}

function parse(value) {
Expand Down
14 changes: 14 additions & 0 deletions src/global/percentage/percentage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ describe('ui-percentage-mask', function() {
expect(model.$viewValue).toBe('100%');
});

it('should hide space before "%" after a model change if ui-hide-space is present', angular.mock.inject(function($rootScope) {
var input = TestUtil.compile('<input ng-model="model" ui-percentage-mask="decimals" ui-percentage-value ui-hide-space>', {
model: 1,
decimals: 0
});

var model = input.controller('ngModel');
expect(model.$viewValue).toBe('100%');

$rootScope.model = 50; // When accessing via rootScope, update model to 50 not 0.5 to represent 50%
$rootScope.$digest();
expect(model.$viewValue).toBe('50%');
}));

it('should allow changing the number of decimals', angular.mock.inject(function($rootScope) {
var input = TestUtil.compile('<input ng-model="model" ui-percentage-mask="decimals">', {
model: '12.345',
Expand Down