Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 7d61a98

Browse files
committed
perf(ngModel): initialize the model $name from $attrs instead of $interpolate per controller
1 parent e790163 commit 7d61a98

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/ng/directive/input.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1728,8 +1728,8 @@ is set to `true`. The parse error is stored in `ngModel.$error.parse`.
17281728
*
17291729
*
17301730
*/
1731-
var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$parse', '$animate', '$timeout', '$rootScope', '$q', '$interpolate',
1732-
function($scope, $exceptionHandler, $attr, $element, $parse, $animate, $timeout, $rootScope, $q, $interpolate) {
1731+
var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$parse', '$animate', '$timeout', '$rootScope', '$q',
1732+
function($scope, $exceptionHandler, $attr, $element, $parse, $animate, $timeout, $rootScope, $q) {
17331733
this.$viewValue = Number.NaN;
17341734
this.$modelValue = Number.NaN;
17351735
this.$$rawModelValue = undefined; // stores the parsed modelValue / model set from scope regardless of validity.
@@ -1747,7 +1747,6 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
17471747
this.$error = {}; // keep invalid keys here
17481748
this.$$success = {}; // keep valid keys here
17491749
this.$pending = undefined; // keep pending keys here
1750-
this.$name = $interpolate($attr.name || '', false)($scope);
17511750

17521751

17531752
var parsedNgModel = $parse($attr.ngModel),
@@ -1757,8 +1756,10 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
17571756
pendingDebounce = null,
17581757
ctrl = this;
17591758

1760-
this.$$setOptions = function(options) {
1759+
this.$$init = function(options, name) {
17611760
ctrl.$options = options;
1761+
ctrl.$name = name;
1762+
17621763
if (options && options.getterSetter) {
17631764
var invokeModelGetter = $parse($attr.ngModel + '()'),
17641765
invokeModelSetter = $parse($attr.ngModel + '($$$p)');
@@ -2527,7 +2528,7 @@ var ngModelDirective = ['$rootScope', function($rootScope) {
25272528
var modelCtrl = ctrls[0],
25282529
formCtrl = ctrls[1] || nullFormCtrl;
25292530

2530-
modelCtrl.$$setOptions(ctrls[2] && ctrls[2].$options);
2531+
modelCtrl.$$init(ctrls[2] && ctrls[2].$options, attr.name);
25312532

25322533
// notify others, especially parent forms
25332534
formCtrl.$addControl(modelCtrl);

test/ng/directive/inputSpec.js

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('NgModelController', function() {
2424
$element: element.find('input'),
2525
$attrs: attrs
2626
});
27+
ctrl.$$init(null, attrs.name);
2728
}));
2829

2930

0 commit comments

Comments
 (0)