I've got a *ngFor where I fetch a heroes list. Now, If I change a value of hero, my heroes should be changed too, how do you do it, the best way...
<li *ngFor="#hero of heroes">
<input type="text" [value]="hero.name"/>
</li>
I only know the way to make a (change)="UpdateListByItem(item)" , to call a methode, but isn't there a way to make a two way databind for all items?
You can do two way databinding using ngModel directive
<li *ngFor="#hero of heroes">
<input type="text" [(ngModel)]="hero.name"/>
</li>
Whenever you change the input text the corresponding hero name will get changed.
More information can be found here https://angular.io/docs/ts/latest/guide/forms.html
You could use ngModel
to do this automatically
<li *ngFor="#hero of heroes">
<input type="text" [(ngModel)]="hero.name"/>
</li>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With