last day (14 days later) » 

1:03 AM
1
A: AngularJS: ng-model setter inside ng-repeat

Wayne ElleryYou would set ng-model to item.title so each object in the array returned from getItems() would contain a title. <div ng-repeat="item in getItems()"> <input type="text" ng-model="item.title"/> </div>

 
How would I create the setter? As it is, all you've done is renamed the variable. The getting isn't the issue; it's the setting.
 
You didn't mention that in your question so I just left it as is. What are you trying to accomplish with ng-model-options={getterSetter:true}
 
I have a dynamic list of items, each with an input box. I'd like to both get the data from each individual box and set it.
 
Without seeing what's in getItems it's difficult to answer, but as long as each item has title set to the title then each textbox will be populated with the title. If the value is changed in the textbox then the item title will be set
 
It doesn't really matter what the array returns. It's just an array with uncertain length that also generates an array of input boxes as ng-repeat iterates. I'm not seeing the code here. Could you elaborate? Sorry. Using the generic getter/setter I use for single values, as I pointed out, just changes all the values.
 
1:03 AM
It does because for my above code to work each item in the array would need to be an object with a title property
 
Sorry, I was trying to set up a JSFiddle
 
So for instance, it would like something like this: plnkr.co/edit/Mf3jyLMKxGfjLDUfBrDq?p=preview
 
Exactly, except the inputs are independent of the item
meaning their values don't come from the item
 
where do the values come from then?
As it's relevant to the item it should really come from the item
That makes it a lot simpler and it doesn't really make sense that each title belongs to each item and not somewhere else
 
I suppose quantity is a good example
 
1:09 AM
so quantity is a dropdown?
 
each item would also have it's own quantity
 
I'm trying to qualify my problem, one sec
Suppose each item is in a catalogue
and our list is the user browsing some search criteria
 
ok, I get you now
 
so the generated boxes would be the amount the used wants to buy
not the quantity of the item itself
 
1:11 AM
I'll need to think for a sec
 
No worries. Thanks for all your input so far.
 
I would probably still associate the quantity with each item as it makes it easier to deal with. Is there any reason that that would cause an issue? If you really needed to you could have a separate array for the quantities. It depends on the situation. Could you only specify quantity once per item?
 
Give me a sec to play with that
Hm. That did it, but I'm not too happy with the result.
But I'm not happy with what I came up with either
Now that I'm thinking about the variable relationships, it makes more sense. Thanks again for your help. Have a good one. I added your chat suggestion to your response and marked it as the answer.
 
1:28 AM
ok, thanks
I'll give you an alternitive in a sec
 
1:53 AM
You could do something like this. plnkr.co/edit/lSx412AHe1d8Ip6ZTIZ7?p=preview
I separated out the item from the quantity
 

last day (14 days later) »