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

feat(ngName): allow interpolated name for form controls #2988

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -1063,9 +1080,6 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
}
};

// model -> value
var ctrl = this;

$scope.$watch(function ngModelWatch() {
var value = ngModelGet($scope);

Expand Down