I'm trying to output html in the following format for an array
weekDaysHeaderArr
whose length is 42 = 6 x 7.
In other words I want to nest every 7 column div elements in a row div (6 total) like so.
<div class="row">
<div class="col-md-auto"> <-- **repeated 7 times**
</div>
</div>
<div class="row">
<div class="col-md-auto"> <-- **repeated 7 times**
</div>
</div>
<div class="row">
<div class="col-md-auto"> <-- **repeated 7 times**
</div>
</div>
<div class="row">
<div class="col-md-auto"> <-- **repeated 7 times**
</div>
</div>
<div class="row">
<div class="col-md-auto"> <-- **repeated 7 times**
</div>
</div>
<div class="row">
<div class="col-md-auto"> <-- **repeated 7 times**
</div>
</div>
I can use ngFor
to obviously produce the same html element (div class="col-md-auto">
) 42 times but how do I nest every 7 elements inside a <div class="row">
?
I've not used ng-template
and ng-container
before and I can't get my head around the documentation, can these be used to do this? As far as I can tell these are designed for switching between html elements rather than nesting.
Create a matrix from your array
Then use it inside your template like this
You can do something like this....
then, to get the index from weekDaysHeaderArr you can do....
Nesting for-loops in angular template is pretty straightforward. Given you have two separate arrays, you can do the following:
I'll update the answer later for the case where you have a nested array already, or can compose one.