Is there a way to set a variable outside of a loop and increment it only when a certain condition is met within the loop?
In Twig, this concept is implemented as follows:
{% for plan in entity.plan %}
{% set spieltag = 0 %} <!-- This sets the variable inside the loop -->
{% if (plan.spieltag != spieltag) %}
<tr class="bg-info">
<td colspan="7">Spieltag: {{ plan.spieltag }}</td>
<td></td>
</tr>
{% set spieltag = spieltag + 1 %} <!-- This increments the variable only when the condition is false -->
{% endif %}
<tr>
<!-- Some content that is always shown -->
</tr>
{% endfor %}
In Angular, a similar concept can be achieved using:
<tr data-ng-repeat="row in liga.plan" data-ng-init="spieltag = 0">
<!-- Content that is repeated for each row -->
</tr>
However, the ng-init directive might not be in the right place. Where should it be placed and how can the variable be incremented only when the specified condition is false?
Sample data from the loop:
[{
plan: [
{spieltag: 1, home: foo, guest: bar},
{spieltag: 1, home: foo1, guest: bar1},
{spieltag: 1, home: foo2, guest: bar2},
{spieltag: 2, home: bar, guest: foo},
{spieltag: 2, home: bar1, guest: foo1},
{spieltag: 2, home: bar2, guest: foo2},
]
}]