opened
uber5001
username_0
**I'm submitting a feature request**

**Current behavior**
A common pattern throughout my application is binding to `ngModel` using a variable provided by *ngFor:
<pre>
&lt;input *ngFor="let foo of listOfFoos; let i = index" [(ngModel)]="listOfFoos[i]">
</pre>
You'll notice I don't even use `foo` here.

**Proposed behavior**
Allow assignment to the local variable `foo` created by *ngFor.
<pre>
&lt;input *ngFor="<b>bind foo</b> of listOfFoos" [(ngModel)]="<b>foo</b>">
</pre>
Keeping the `let` syntax would be confusing for this feature, as `let` implies a local variable. A variable with `bind` would have the side effect of assigning to it's original source, more like an alias than a variable. If this is implemented, a `bind` variable would likely require a `trackBy` to know what index to assign its new values to.

**Minimal reproduction of the problem with instructions**
[Here's a simple example on plunker](https://plnkr.co/edit/jgYbUzTy8q3l1fpCJIE9?p=preview). The desired behavior is commented out. Note that I included `trackBy` to get this example to work, and I don't expect that to go away with the new proposed behavior.

**What is the motivation / use case for changing the behavior?**
Being able to bind to the array element's *ngFor variable (`foo`, in this case) seems like it should "just work", like in #8602 and #8086.

**Please tell us about your environment:**
<!-- Operating system, IDE, package manager, HTTP server, ... -->

* **Angular version:** 4.1.3
<!-- Check whether this is still an issue in the most recent Angular version -->

* **Browser:** all
<!-- All browsers where this could be reproduced -->
 
* **Language:** TypeScript 2.1

* **Node (for AoT issues):** `node --version` =   `v6.10.2`
Allow assignment to the local variable created by *ngFor.
issue
created
trotyl
username_1
Possibly duplicate of #8602.
comment
created
pkozlowski-opensource
username_2
If this local variable bothers you there is the de-sugared syntax that you could use (which is closer to the for loop with indexes):

```html
<ng-template ngFor [ngForOf]="listOfFoos" let-i="index">
    <input [(ngModel)]="listOfFoos[i]">
</ng-template>
``` 

which is closer to the JS loop (not saying that it is easier to write but probably makes the intention clearer).

tl;dr; I understand what you are asking for but we will pass on the suggestion for now as it would introduce syntax and constructs that would make us (even) more different from the standard JS behaviour.
comment
closed
pkozlowski-opensource
username_2
issue