Using ngModel with ngFor


#1

I’m trying to use ngFor to bind object value from an object list/array to an Ion-Input field;
e.g. Array< User > --> [ngModel]=“user.name”.
This works like it should when I’m using it without ngFor. It binds the value from the object to the Inputfield and the Inputvalue to the object.
Inside of a ngFor it just binds the object initial value to the Inputfield but not the other way.
I searched for a while and found that this seemed to be a Bug in earlyer versions of Ionic2 and I tryed some “fixes” that seems to work when using ion-input in forms:

<ion-input item-left type="number" [ngModel]="user.workedHours" name={{user.ID}}>
<ion-input item-left type="number" [ngModel]="user.workedHours" id={{user.ID}}>

But that and a few other options didn’t worked for me.
I don’t know if I just missed the Fix for this in a ngFor or I’m just missing anything.

Would be great if some of you can help me or tell me that this is not just happening to me :smile:

PS: I got a work around with the blur event with something like that: (blur)=“saveValue(user)”


#2

hi @MarvinS
you need to understand the difference between an attribute and a property of an element

seems this will help you ,if you understand the concept you know your mistake there

if you are not able to identify the solution i will update it


#3

@Thavarajan thank you for your respond!

At first, thats a great article thx for that!
After reading that I feel a bit dumb. I allready knew about the difference between an attribute and a property of an element but after working for the whole day and then just stuck because i didn’t realiesed that i missed those normal brackets is a bit annoying :weary:
I just controlled that part over and over again but didn’t realised that …

Anyway thx for your response it was an enrichment to read that article and refresh those informations! :slight_smile:

Have a nice weekend :slight_smile: