MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / numberInputType

Function numberInputType

code/songhop/www/lib/angular/angular.js:19803–19855  ·  view source on GitHub ↗
(scope, element, attr, ctrl, $sniffer, $browser)

Source from the content-addressed store, hash-verified

19801}
19802
19803function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
19804 badInputChecker(scope, element, attr, ctrl);
19805 baseInputType(scope, element, attr, ctrl, $sniffer, $browser);
19806
19807 ctrl.$$parserName = 'number';
19808 ctrl.$parsers.push(function(value) {
19809 if (ctrl.$isEmpty(value)) return null;
19810 if (NUMBER_REGEXP.test(value)) return parseFloat(value);
19811 return undefined;
19812 });
19813
19814 ctrl.$formatters.push(function(value) {
19815 if (!ctrl.$isEmpty(value)) {
19816 if (!isNumber(value)) {
19817 throw $ngModelMinErr('numfmt', 'Expected `{0}` to be a number', value);
19818 }
19819 value = value.toString();
19820 }
19821 return value;
19822 });
19823
19824 if (attr.min || attr.ngMin) {
19825 var minVal;
19826 ctrl.$validators.min = function(value) {
19827 return ctrl.$isEmpty(value) || isUndefined(minVal) || value >= minVal;
19828 };
19829
19830 attr.$observe('min', function(val) {
19831 if (isDefined(val) && !isNumber(val)) {
19832 val = parseFloat(val, 10);
19833 }
19834 minVal = isNumber(val) && !isNaN(val) ? val : undefined;
19835 // TODO(matsko): implement validateLater to reduce number of validations
19836 ctrl.$validate();
19837 });
19838 }
19839
19840 if (attr.max || attr.ngMax) {
19841 var maxVal;
19842 ctrl.$validators.max = function(value) {
19843 return ctrl.$isEmpty(value) || isUndefined(maxVal) || value <= maxVal;
19844 };
19845
19846 attr.$observe('max', function(val) {
19847 if (isDefined(val) && !isNumber(val)) {
19848 val = parseFloat(val, 10);
19849 }
19850 maxVal = isNumber(val) && !isNaN(val) ? val : undefined;
19851 // TODO(matsko): implement validateLater to reduce number of validations
19852 ctrl.$validate();
19853 });
19854 }
19855}
19856
19857function urlInputType(scope, element, attr, ctrl, $sniffer, $browser) {
19858 // Note: no badInputChecker here by purpose as `url` is only a validation

Callers

nothing calls this directly

Calls 5

badInputCheckerFunction · 0.70
baseInputTypeFunction · 0.70
isNumberFunction · 0.70
isUndefinedFunction · 0.70
isDefinedFunction · 0.70

Tested by

no test coverage detected