1

I have following structure parent can have multiple children and children will have an objective. I need to show this in editable table, but when I bind the model within the input of objective, it updates all other selected children's objective too.

here is code

select same childrens from two row's options, and edit the objective of one children it will reflect in other row as well.

<tbody>
        <tr ng-repeat-start="parent in records" ng-class-even="'striped'">
            <!--KPI-->
            <td><strong>{{parent.name}}</strong></td>
            <!-- controls -->
            <td tool-tips class="inputs">
                <select
                        ng-model="parent.childrens"
                        ng-options="item as item.name for item in controlTypes"
                        multiple='multiple'>
                </select>
            </td>
            <!-- Controls objective-->
            <td colspan="1"/>
            </td>
        </tr>
        <tr ng-if="parent.childrens.length>0"
            ng-repeat="child in parent.childrens">
            <td name="process" colspan="2" style="word-wrap:break-all;" align="right">{{child.name}}
            </td>
            <!-- Controls objective-->
            <td>
                <input type="text" class="ultra-short" ng-model="child.objective"
                       maxlength="200"/>
            </td>

        </tr>
        <tr ng-repeat-end></tr>
        </tbody>

Any help please.

||||||
1

As far as I can tell it woun't work with such structure, because all you do is work with references. When you change some options objective property you actually change it everywhere in same option, because you are working with reference.

UPDATE:
One way to handle this

||||||
  • What is the proper way to solve this scenario? I have used @Nikhilish K V solution. Don't know what is $rootIndex but it creates an undefined propety in parent and I can access the childrens using paren[parentIndex].undefined.childrens[index].objective. definitely it is not solution but at moment used at urgency. – veshu May 18 '16 at 3:26
  • While it(2-way binding) works with nested ng-repeat, is it the problem with ng-repeat-start only? – veshu May 18 '16 at 3:29
0

If you want the model to be different for each iteration of the ng-repeat:

<div ng-repeat="parent in parents">
  <select
    ng-model="vm.model.parent.item"
    ng-options="item as item.name for item in controlTypes"
    multiple="multiple">
  </select>
</div>

Now you have a different model for each iteration, is this what you were looking to do?

||||||
  • Did you selected the options in two row and try to edit the objective. problem is not select, I want the objective of children to be set in the correspoinding parent – veshu May 14 '16 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.