Storage: Could not find 'BlazorExtensions' in 'window' (Server mode)
In a new project, using server side template, I added the reference to BlazorExtensions storage (0.2.1), added the services.AddStorage() line to register the services. If I modify the counter example to this:
`@page “/counter” @using Blazor.Extensions.Storage @inject SessionStorage sessionStorage @inject LocalStorage localStorage
Counter
Current count: @currentCount
<button class=“btn btn-primary” @onclick=“IncrementCount”>Click me</button>
@code { int currentCount = 0;
async void IncrementCount()
{
currentCount=await localStorage.GetItem<int>("counter");
currentCount++;
localStorage.SetItem("counter", currentCount).Wait();
}
} ` I receive the error Could not find ‘BlazorExtensions’ in ‘window’. blazor.server.js is present in Sources when I enter in dev mode in chrome. dotnet --version outputs 3.0.100-preview7-012821.
Is that correct?
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 1
- Comments: 17 (1 by maintainers)
Add this to your
index.html
or_Host.cshtml
whichever you are using:<script type="text/javascript" src="_content/Blazor.Extensions.Storage.JS"></script>
Should the
blazor.extensions.storage.js
file not get automatically generated clone this github repo and build the solution. You should then find the compiled js there inside the dist folder, then just copy it over to your project in/bin/Debug/netstandardx.x/dist/_content/
If i compile the .ts scripts, put in wwwroot and init the script directly in _host.cshtml it works, so I think is related to https://github.com/BlazorExtensions/Storage/issues/24
hope so!