I try to show a spinner while loading the data. The spinner worked just fine, as long as i didn't explictly made all the calls asnyc. But since I change to async calls, it seems that the StateChanges of the two variable isLoading and emptyResult won't be recognized. Everything else just runs as it should and after a view seconds my the table is shown, but i never get the spinner. What am I missing here?
<EditForm Model="@parameter" OnValidSubmit="@Submit">
...
</EditForm>
@if (isLoading && !emptyResult)
{
<div class="spinner"></div>
}
else if(!isLoading && emptyResult)
{
<div>
<span class="text-danger">
No data for given parameters.
</span>
</div>
}
else if (data != null && !isLoading && !emptyResult)
{
//Table of data
}
@code{
private MyParameter parameter = new MyParameter();
private List<CustomObject> data;
private bool isLoading = false;
private bool emptyResult = false;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
}
private async Task Submit()
{
emptyResult = false;
isLoading = true;
await LoadDataAsync();
isLoading = false;
}
private async Task LoadDataAsync()
{
data = await service.GetData(parameter);
if(data is null)
{
emptyResult = true;
}
else {
//Some calculation on data
}
}
}