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

Commit d20de4a

Browse files
yankee42Narretz
authored andcommitted
docs(ngModel): use arguments.length instead of angular.isDefined(newName) to distinguish getter/setter usage
Closes #11604
1 parent 071b1bc commit d20de4a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/ng/directive/ngModel.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -996,10 +996,11 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
996996
var _name = 'Brian';
997997
$scope.user = {
998998
name: function(newName) {
999-
if (angular.isDefined(newName)) {
1000-
_name = newName;
1001-
}
1002-
return _name;
999+
// Note that newName can be undefined for two reasons:
1000+
// 1. Because it is called as a getter and thus called with no arguments
1001+
// 2. Because the property should actually be set to undefined. This happens e.g. if the
1002+
// input is invalid
1003+
return arguments.length ? (_name = newName) : _name;
10031004
}
10041005
};
10051006
}]);
@@ -1217,7 +1218,11 @@ var DEFAULT_REGEXP = /(\s+|^)default(\s+|$)/;
12171218
var _name = 'Brian';
12181219
$scope.user = {
12191220
name: function(newName) {
1220-
return angular.isDefined(newName) ? (_name = newName) : _name;
1221+
// Note that newName can be undefined for two reasons:
1222+
// 1. Because it is called as a getter and thus called with no arguments
1223+
// 2. Because the property should actually be set to undefined. This happens e.g. if the
1224+
// input is invalid
1225+
return arguments.length ? (_name = newName) : _name;
12211226
}
12221227
};
12231228
}]);

0 commit comments

Comments
 (0)