Skip to content

Commit a699721

Browse files
committed
refactor(ngModel): use minErr directly for correct doc creation
The minerr_errors extractor of the closure compiler cannot detect minErrs that are not thrown in the form of 'throw minErr(...' Closes angular#12386
1 parent d935c24 commit a699721

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/ng/directive/input.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
DIRTY_CLASS: false,
77
UNTOUCHED_CLASS: false,
88
TOUCHED_CLASS: false,
9-
$ngModelMinErr: false,
109
*/
1110

1211
// Regex code is obtained from SO: https://stackoverflow.com/questions/3143070/javascript-regex-iso-datetime#answer-3143231
@@ -1239,7 +1238,7 @@ function createDateInputType(type, regexp, parseDate, format) {
12391238

12401239
ctrl.$formatters.push(function(value) {
12411240
if (value && !isDate(value)) {
1242-
throw $ngModelMinErr('datefmt', 'Expected `{0}` to be a date', value);
1241+
throw minErr('ngModel')('datefmt', 'Expected `{0}` to be a date', value);
12431242
}
12441243
if (isValidDate(value)) {
12451244
previousDate = value;
@@ -1315,7 +1314,7 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) {
13151314
ctrl.$formatters.push(function(value) {
13161315
if (!ctrl.$isEmpty(value)) {
13171316
if (!isNumber(value)) {
1318-
throw $ngModelMinErr('numfmt', 'Expected `{0}` to be a number', value);
1317+
throw minErr('ngModel')('numfmt', 'Expected `{0}` to be a number', value);
13191318
}
13201319
value = value.toString();
13211320
}

src/ng/directive/ngModel.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ var VALID_CLASS = 'ng-valid',
1616
TOUCHED_CLASS = 'ng-touched',
1717
PENDING_CLASS = 'ng-pending';
1818

19-
20-
var $ngModelMinErr = new minErr('ngModel');
21-
2219
/**
2320
* @ngdoc type
2421
* @name ngModel.NgModelController
@@ -268,7 +265,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
268265
}
269266
};
270267
} else if (!parsedNgModel.assign) {
271-
throw $ngModelMinErr('nonassign', "Expression '{0}' is non-assignable. Element: {1}",
268+
throw minErr('ngModel')('nonassign', "Expression '{0}' is non-assignable. Element: {1}",
272269
$attr.ngModel, startingTag($element));
273270
}
274271
};
@@ -599,7 +596,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
599596
forEach(ctrl.$asyncValidators, function(validator, name) {
600597
var promise = validator(modelValue, viewValue);
601598
if (!isPromiseLike(promise)) {
602-
throw $ngModelMinErr("$asyncValidators",
599+
throw minErr('ngModel')("$asyncValidators",
603600
"Expected asynchronous validator to return a promise but got '{0}' instead.", promise);
604601
}
605602
setValidity(name, undefined);

0 commit comments

Comments
 (0)