diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 591da99e3b8d..4b3f9583f5b0 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -924,6 +924,23 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ this.$invalid = false; this.$name = $attr.name; + // model -> value + var ctrl = this; + + if (isDefined($attr.ngName)) { + ctrl.$name = $scope.$eval($attr.ngName); + $attr.$set('name', ctrl.$name); + $attr.$observe('ngName', function() { + var newName = $scope.$eval($attr.ngName); + if (newName != ctrl.$name) { + parentForm.$removeControl(ctrl); + ctrl.$name = newName; + $attr.$set('name', ctrl.$name); + parentForm.$addControl(ctrl); + } + }); + } + var ngModelGet = $parse($attr.ngModel), ngModelSet = ngModelGet.assign; @@ -1063,9 +1080,6 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ } }; - // model -> value - var ctrl = this; - $scope.$watch(function ngModelWatch() { var value = ngModelGet($scope);