-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Arrays of strings not being handled properly within ng-repeat #1267
Comments
I am assuming you had this: <div ng-repeat="value in model.values"> <input type="text" ng-model="value" /> </div> this will not work since you are binding to a scope. Basically you have to have a so this is basically expected because you are binding to a scope.value property not to the original value in the repeater. The flicker is also expected with your workaround since data binding changes the array, which then makes it look like to the repeater as if I know this is counter intuitive, but that is how the system is architected. Don't bind to primitives is my answer. |
Thank you for the follow up. I'll adjust my data structure to take this into account. |
My example doesn't work too: http://jsfiddle.net/nicholas_r/7KrQ5/ I followed the solution given here but it didn't give any effect and the problem is still here. |
The solution given here says, "you have to have a |
Oh, my fault. Thanks. |
I would like to submit having this work as a feature request (although I recognize that's unlikely, given the response to this issue so far haha). Is this comment sufficient to do so, or should I open a new issue? |
Have you tried this version of the ng-repeat directive? |
I'm requesting a feature where you can bind directly to a string within an ng-repeat. |
You can do that now. I suspect what you mean is that you want the scope outside the ng-repeat to update when the string is updated? |
Yes, I would like to be able to use I understand why it doesn't work now, and realize that making it work could be more trouble than it's worth, but I think it's worth looking in to because it would make angular easier to work with. |
The only way to make it work without changing the way that Javascript works This allows you to reference the element directly so that changes are But this doesn't work correctly with the current ng-repeat implementation On 12 December 2012 15:35, Nick Heiner notifications@github.com wrote:
|
Yep, that works. Thanks! |
This works in angular 1.1.4- (repeating an array of strings) |
Here's a way to effectively bind the members of a string array to a UI component. I used textarea boxes, but it could be done the same with an input or whatever: |
Hi, Please I need to bind a text field to each row in a ng-repeat. I want the text field to have different value for each row. My ng-model is instead binding one value to all the textfield in my ng-repeat. Please how do you advise I proceed. |
Ok I figured out a way to get it to work using the latest version of angular. If the size of the array won't change then you can use one time binding like so: <li ng-repeat="str in ::arrayOfStrings">
<input ng-model="arrayOfStrings[$index]" />
<br/>
</li> This will prevent the repeat from changing the dom and changes to the primitives will be watched correctly. |
I was able to work around this and use avoid the issue with lost focus by using track by (tested against ver 1.3) <div ng-repeat="value in model.values track by $index">
<input type="text" ng-model="model.values[$index]">
</div> |
toboid: thanks for sharing that workaround! I was in a situation where restructuring my array data to an array of objects would have been very cumbersome (in recursive directive views). Track by $index helped. I'm wondering why 'track by' fixes this issue though? What is the underlying reason? |
thanks @toboid sloved my problem, it works. if you do not want wrap a object in array <div ng-repeat="value in model.values track by $index">
<input type="text" ng-model="model.values[$index]">
</div> |
I have created form with radio buttons dynamically with sample as above in which i could not get the form data values while submit action.please guide how to resolve |
In the above sample ng-model not working with ng-repeat . while form submit it gives only undefined value in console.... |
@gissivaraman open a new ticket and please follow the basic guidelines for submitting an issue. Don't tack your issues onto another. |
When displaying a series of values from an array, the data items are not being bound to the model properly, as in:
If the above is displayed in a series of input fields, changes to the content are not reflected in the model. However, binding the above using code like the following does maintain binding to the model:
However the issue with this approach is that the text field loses focus on each keyup. A demo is here:
http://jsfiddle.net/donovanh/GSx76/
The text was updated successfully, but these errors were encountered: