0

Question might be hard to understand but my problem is simple:

  • I want to display a list of contacts.
  • I'm displaying them as cards using bootstrap
  • I want each row to show 4 cards

HTML structure:

  <div class="row" *ngFor="let contact of contacts">
    <!-- Here I want to loop 4 of the contacts before rendering a new row -->
    <div class="col-md-3"> 
      <contact-card [contact]="contact"></contact-card>
    </div>
  </div>

Or more simplified, I want to do achieve this: enter image description here

Is there a way to do an "inner" ngFor in col-md-3 div, which stops after rendering 4 contacts?

Weblurk
  • 6,562
  • 18
  • 64
  • 120

1 Answers1

0

You could create two components: one to display a single card, and second - to display a row of cards.

More code overall, but each component is simpler, more cohesive and reusable; the two components are decoupled.

At last, you could process all the cards' data as stream and form batches of required amount of cards to fill rows.

iTollu
  • 999
  • 13
  • 20