Interface ILoadingService
- Namespace
- NuvTools.AspNetCore.Blazor.Services
- Assembly
- NuvTools.AspNetCore.Blazor.dll
Provides a service for managing loading indicator state.
public interface ILoadingService
Remarks
Use this service to coordinate loading overlays across components. Register as scoped in DI and inject where needed.
@inject ILoadingService LoadingService
<div class="loading-overlay" style="display: @(LoadingService.IsLoading ? "block" : "none")">
Loading...
</div>
@code {
protected override void OnInitialized()
{
LoadingService.OnChange += StateHasChanged;
}
public void Dispose()
{
LoadingService.OnChange -= StateHasChanged;
}
}
Properties
IsLoading
Gets a value indicating whether the loading indicator should be shown.
bool IsLoading { get; }
Property Value
Methods
Hide()
Hides the loading indicator.
void Hide()
RunAsync(Func<Task>)
Executes an async operation while showing the loading indicator. Automatically hides the indicator when complete, even if an exception occurs.
Task RunAsync(Func<Task> work)
Parameters
Returns
- Task
A task representing the async operation.
Show()
Shows the loading indicator.
void Show()
Events
OnChange
Occurs when the loading state changes.
event Action? OnChange