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

Commit 5183eeb

Browse files
committed
perf(ngModel): initialize the model $name from $attrs instead of $interpolate per controller
1 parent 1a45b60 commit 5183eeb

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Diff for: src/ng/directive/input.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1694,8 +1694,8 @@ var VALID_CLASS = 'ng-valid',
16941694
*
16951695
*
16961696
*/
1697-
var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$parse', '$animate', '$timeout', '$rootScope', '$q', '$interpolate',
1698-
function($scope, $exceptionHandler, $attr, $element, $parse, $animate, $timeout, $rootScope, $q, $interpolate) {
1697+
var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$parse', '$animate', '$timeout', '$rootScope', '$q',
1698+
function($scope, $exceptionHandler, $attr, $element, $parse, $animate, $timeout, $rootScope, $q) {
16991699
this.$viewValue = Number.NaN;
17001700
this.$modelValue = Number.NaN;
17011701
this.$validators = {};
@@ -1712,7 +1712,6 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
17121712
this.$error = {}; // keep invalid keys here
17131713
this.$$success = {}; // keep valid keys here
17141714
this.$pending = undefined; // keep pending keys here
1715-
this.$name = $interpolate($attr.name || '', false)($scope);
17161715

17171716

17181717
var parsedNgModel = $parse($attr.ngModel),
@@ -1738,8 +1737,9 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
17381737
}
17391738
};
17401739

1741-
this.$$setOptions = function(options) {
1740+
this.$$init = function(options, name) {
17421741
ctrl.$options = options;
1742+
ctrl.$name = name;
17431743

17441744
if (!parsedNgModel.assign && (!options || !options.getterSetter)) {
17451745
throw $ngModelMinErr('nonassign', "Expression '{0}' is non-assignable. Element: {1}",
@@ -2434,7 +2434,7 @@ var ngModelDirective = function() {
24342434
var modelCtrl = ctrls[0],
24352435
formCtrl = ctrls[1] || nullFormCtrl;
24362436

2437-
modelCtrl.$$setOptions(ctrls[2] && ctrls[2].$options);
2437+
modelCtrl.$$init(ctrls[2] && ctrls[2].$options, attr.name);
24382438

24392439
// notify others, especially parent forms
24402440
formCtrl.$addControl(modelCtrl);

Diff for: 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)