This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
ng-required="true" does not allow to empty field when using ng-model-options="{ getterSetter: true }" #11361
Closed
Description
When using both ng-required="true" and ng-model-options="{ getterSetter: true }",
there is no possibility to empty the field. You always get the last character 'standing' in the input field.
This happens because 'newName' value in getter-setter function for name is undefined when value is empty. It happens only when using ng-required="true". If the field is not required, we get just empty string and everyrhing works fine.
Here is the code example:
<input type="text" name="userName"
ng-required="true"
ng-model="user.name"
ng-model-options="{ getterSetter: true }" />
(function(angular) {
'use strict';
angular.module('getterSetterExample', [])
.controller('ExampleController', ['$scope', function($scope) {
var _name = '';
$scope.user = {
name: function(newName) {
console.log(newName);
if (angular.isDefined(newName)) {
_name = newName;
}
return _name;
}
};
}]);
})(window.angular);