angular/angular.js — pull request #6569 by sjbarker (2014-03-06 04:13:49+00:00)
Title: feat(directive): ngName

Currently there are multiple pull requests for an end result that it seems multiple people want - an evaluated control name. Doing so through binding causes issues with maintaining the adding and removing of controls to their parent. Most (if not, all) open issues on this subject make changes to the NgModelController. I approached it this way to avoid making any changes in existing controllers or directives (so this is a genuine "new" feature) and prevents changes on the expression from mucking up the controls.

The NgModelController is instantiated prior to the markup being compiled. So currently the following will not work either:
```html

```

The `name` attribute will be set on the element, however the `$name` property on the controller would be `"{{ myControl }}"`.

This commit accomplishes the task through the use of a directive. Consider the following markup:
```html

```

Where the scope expressions may be:
```javascript
scope.something = 123;
scope.myControl = "testControl";
```

The order we are concerned with is getting the `$name` property on the NgModelController for this control to be `"testControl"` and equally importantly, prior to the control being added to the parent form (if it exists).

This directive jumps in between the NgModelController instantiation and the ngModel linking function to set the `name` attribute and property and the `$name` controller property, prior to the control being added.

So, for a final example, if you wanted to build your form with `ng-repeat` using a data model:
```html

True or false, am I $valid? -

thisForm.controlA1.$valid = {{ thisForm.controlA1.$valid }}
...
```
```javascript
scope.controls = [
{
code: 'A1',
val: ''
},
{
code: 'B2',
val: ''
},
{
code: 'C1',
val: ''
}
];