Add stringToNumber directive

This commit is contained in:
Marliana Lara 2018-01-29 11:09:00 -05:00 committed by Matthew Jones
parent 368101812c
commit 342958ece3
No known key found for this signature in database
GPG Key ID: 76A4C17A97590C1C

View File

@ -38,7 +38,7 @@ angular.module('AWDirectives', ['RestServices', 'Utilities'])
};
})
// caplitalize Add to any input field where the first letter of each
// capitalize Add to any input field where the first letter of each
// word should be capitalized. Use in place of css test-transform.
// For some reason "text-transform: capitalize" in breadcrumbs
// causes a break at each blank space. And of course,
@ -65,6 +65,26 @@ angular.module('AWDirectives', ['RestServices', 'Utilities'])
};
})
// stringToNumber
//
// If your model does not contain actual numbers then this directive
// will do the conversion in the ngModel $formatters and $parsers pipeline.
//
.directive('stringToNumber', function() {
return {
require: 'ngModel',
restrict: 'A',
link: function(scope, element, attrs, ngModel) {
ngModel.$parsers.push(function(value) {
return '' + value;
});
ngModel.$formatters.push(function(value) {
return parseFloat(value);
});
}
};
})
// imageUpload
//
// Accepts image and returns base64 information with basic validation