Looping Loops with Angularjs

Asked

Viewed 1,028 times

1

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

In 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 lists the inputs of these forms (fields)

This information is retrieved via localStorage from a JSON.

  • Show the controller you set up to populate this li ai, maybe that’s the problem.

1 answer

2


It seems to me that your second ng-repeat retrieves information from a variable g which must only exist within the element to which the first is attached ng-repeat.

Maybe it’s not what you want, but then it shouldn’t 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, because inside the <li ng-repeat="g in formulario.grupos">...</li> the variable g exists.

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

  • 1

    It worked Rik! Thank you :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.