Repeat loops with AngularJS

1

I'm trying to list the data of two loops ng-repeat of my code, but 1 of them is not working.

In this case, I'm using:

<ul class="nav nav-stacked nav-pills col-md-2" >
  <li ng-repeat="g in formulario.grupos">
      <a data-target="{{g.titulo}}" data-toggle="tab">{{g.titulo}}</a>
  </li>
</ul>

<!-- Tab panes -->
<div class="tab-content col-md-10" style="border:#000; border-radius:5px;">
  <div class="tab-pane" id="" ng-repeat="c in g.campos" >
      <input type="" ng-model="c.campo" name="" value="" class="form-control" > <!--ng-repeat="campo in g.campos"-->
  </div>
</div>

My problem is there. The first loop brings the forms (groups) and the second list the inputs of these forms (fields)

This information is retrieved via localStorage from a JSON.

    
asked by anonymous 07.02.2014 / 18:19

2 answers

2

What I think is that your second ng-repeat will fetch information from a g variable that should only exist within the element to which the first ng-repeat is bound.

Maybe it's not what you want, but it should not give you any more trouble:

<ul class="nav nav-stacked nav-pills col-md-2" >
  <li ng-repeat="g in formulario.grupos">
    <a data-target="{{g.titulo}}" data-toggle="tab">{{g.titulo}}</a>
    <!-- Tab panes -->
    <div class="tab-content col-md-10" style="border:#000; border-radius:5px;">
      <div class="tab-pane" id="" ng-repeat="c in g.campos" >
        <input type="" ng-model="c.campo" name="" value="" class="form-control" > <!--ng-repeat="campo in g.campos"-->
      </div>
    </div>
  </li>
</ul>

This is because within <li ng-repeat="g in formulario.grupos">...</li> the variable g exists.

Tell me if it worked, and if at least you got the solution. Good luck;)

    
07.02.2014 / 20:11
0

It's just a matter of scope, in the second ng-repeat, the variable g does not exist. You can try this:

<ul class="nav nav-stacked nav-pills col-md-2" >
  <li ng-repeat="g in formulario.grupos">
      <a data-target="{{g.titulo}}" data-toggle="tab">{{g.titulo}}</a>
  </li>
</ul>

<!-- Tab panes -->

<div class="tab-content col-md-10" ng-repeat="g in formulario.grupos" style="border:#000; border-radius:5px;">
  <div class="tab-pane" id="" ng-repeat="c in g.campos" >
      <input type="" ng-model="c.campo" name="" value="" class="form-control" > <!--ng-repeat="campo in g.campos"-->
  </div>
</div>
    
14.02.2014 / 15:49