diff --git a/README.md b/README.md index 69e9de4..3d96c41 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This package provides Blazor applications with access to the browser's [Geolocat public void ConfigureServices(IServiceCollection services) { ... - services.AddSingleton(); + services.AddScoped(); ... } ``` @@ -33,14 +33,24 @@ This package provides Blazor applications with access to the browser's [Geolocat Accuracy: @location?.Accuracy
- @functions - { - Location location; - - protected override async Task OnInitAsync() - { - location = await LocationService.GetLocationAsync(); - } + @functions + { + Location location = null; + + protected async Task GetLocation() + { + location = await LocationService.GetLocationAsync(); + this.StateHasChanged(); + } + + protected override async Task OnAfterRenderAsync(bool first) + { + if (first) + { + base.OnAfterRender(first); + await GetLocation(); + } + } } ```