Skip to content

Commit

Permalink
fix(number): fix the result for 0 and other edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
assisrafael committed Apr 7, 2015
1 parent 31c7d51 commit ba9bdf7
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/global/number/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ angular.module('ui.utils.masks.global.number', [
var viewMask = NumberMasks.viewMask(decimals, decimalDelimiter, thousandsDelimiter),
modelMask = NumberMasks.modelMask(decimals);

function parse(value) {
if(!value) {
function parser(value) {
if(ctrl.$isEmpty(value)) {
return value;
}

Expand Down Expand Up @@ -54,21 +54,22 @@ angular.module('ui.utils.masks.global.number', [
return actualNumber;
}

ctrl.$formatters.push(function(value) {
function formatter(value) {
if(ctrl.$isEmpty(value)) {
return value;
}

var prefix = '';
if(angular.isDefined(attrs.uiNegativeNumber) && value < 0){
prefix = '-';
}

if(!value) {
return value;
}

var valueToFormat = PreFormatters.prepareNumberToFormatter(value, decimals);
return prefix + viewMask.apply(valueToFormat);
});
}

ctrl.$parsers.push(parse);
ctrl.$formatters.push(formatter);
ctrl.$parsers.push(parser);

if (attrs.uiNumberMask) {
scope.$watch(attrs.uiNumberMask, function(decimals) {
Expand All @@ -78,7 +79,7 @@ angular.module('ui.utils.masks.global.number', [
viewMask = NumberMasks.viewMask(decimals, decimalDelimiter, thousandsDelimiter);
modelMask = NumberMasks.modelMask(decimals);

parse(ctrl.$viewValue || '');
parser(ctrl.$viewValue);
});
}

Expand Down

0 comments on commit ba9bdf7

Please sign in to comment.