using services for component communication blazor code example
Example 1: how to pass property between blazor components
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<Services.AppData>();
}
Example 2: how to pass property between blazor components
@page "/page2"
@inject Services.AppData AppData
<h1>Second Page</h1>
<div style="width:640px; height:480px; background-color:@AppData.Color">
<p>You entered the number @AppData.Number.</p>
</div>
@code {
protected override void OnInitialized()
{
AppData.OnChange += StateHasChanged;
}
}