1

when table inside table repeating dynamically in that time ng-if is not working.when am adding one row in child table in that time taking wrong parent index.am using like that but in input filed working fine but buttons are not working when ng-if condition taking wrong parent index

eg:

<div  id="parentdivId" ng-repeat="parent in listOfParentTables">

            <table >
            <thead class="evlhead ingpopuphead">
              <tr>
                <th >A</th>
                <th >B</th>               
                <th >C</th> 
              </tr>
            </thead> 

            <tbody >
             <tr  ng-repeat="child in parent.childMaster" ng-if="child.status!=2">  
             <td > 
              <select   id="a10" ng-model="child.a10">
               <option ng-repeat="list in listMaster" value={{list.ID}}>{{list.NAME}}</option>
              </select>  
              </td> 
             <td ><div class="addrembtn" ><input class="btnadd" type="button" value="+" id="addbutton10"  ng-click="addNewChildRow($parent.$index,$index)"><input class="btnrem" type="button" value="-" id="deletebutton10"  ng-click="removechildRow($parent.$index,$index)"></div></td>
            </tr>
               </tbody> 
           </table>


           <div style="float:left;"> 
            <button class="parentbtn" style="margin:37px 0px 0px 17px !important;width: 75px;" value="AddTable" id="basebutton" ng-click="addNewParenttable($index)">+ &nbsp;Gasto</button>
          </div>
          <div style="float:left;"> 
            <button class="parentbtn" style="margin: 12px 0px 0px 17px !important;width: 75px;" value="AddTable" id="basebutton" ng-click="removeParenttable($index)">- &nbsp;Eliminar</button>
          </div>

           </div>
3
  • show the full table with ng repeat Commented Jun 16, 2017 at 6:34
  • Refer to my answer on stackoverflow.com/questions/20111636/…. It might help you Commented Jun 16, 2017 at 6:35
  • In above code when ng-if condtion removed it is working fine but I wanna put that condion Commented Jun 16, 2017 at 6:45

1 Answer 1

2

In a nested ng-repeat, the $index does not give the index of element in the array being iterated. Use something like,

ng-click="addNewChildRow(listOfParentTables.indexOf(parent),parent.childMaster.indexOf(child))"
ng-click="addNewParenttable(listOfParentTables.indexOf(parent))"

indexOf always returns the original index in an ng-repeat Plunker

Hope it helps!

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for replay.Ill try this one.
Thanks alot :) Happy to help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.