I have a page that loads a list of items in C# Blazor. I am trying to figure out a way that a spinner shows until my foreach loop has itereated all list items. This is my current code:
@foreach (var f in FlyersState.Value.Flyers)
{
@if (isLoading)
{
<div class="spinner"></div>
}
else
{
<tr>
<td class="clickable" @onclick="()=>OpenFlyerDetails(f)">
@f.DealNo
<a href="flyers/@(f.Id)" target="_blank"><i class="fas fa-external-link-alt"></i></a>
</td>
<td>@f.Range</td>
<td>@f.Id</td>
<td>
<a class=" float-right" href="" data-target="#flyerModal" data-toggle="modal" @onclick="(() => EditFlyer(f))">
<i class="fas fa-edit"></i>
</a>
</td>
<td>
<a class=" float-right" href="" data-target="#confirmModal" data-toggle="modal" @onclick="(() => ShowDeleteConfirmAtionDialog(f))">
<i class="far fa-trash-alt"></i>
</a>
</td>
</tr>
}
}
and this is how my page is initialized:
private Flyer selectedFlyer => FlyersState.Value.SelectedFlyer;
private bool isLoading = true;
Flyer flyer = new Flyer();
protected override void OnInitialized()
{
base.OnInitialized();
Dispatcher.Dispatch(new LoadFlyersAction());
}
The problem I am running into is I am unsure of how to turn isLoading to false when the loop is done iterating my table. Any help would be appreciated.