I have followed the installation instructions from https://www.matblazor.com/.
1.Add @using MatBlazor in main _Imports.razor
@using MatBlazor
2.Add script section to index.html (head section)
<script src="_content/MatBlazor/dist/matBlazor.js"></script>
<link href="_content/MatBlazor/dist/matBlazor.css" rel="stylesheet" />
3.Add registration of service to Startup.cs
services.AddMatBlazor();
4.Add MatPortalHost component to root component (App.razor) for some services like MatDialogService, MatPortalService
<MatPortalHost></MatPortalHost>
Error when starting:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Cannot provide a value for property 'PortalService' on type 'MatBlazor.MatPortalHost'. There is no registered service of type 'MatBlazor.IMatPortalService'. System.InvalidOperationException: Cannot provide a value for property 'PortalService' on type 'MatBlazor.MatPortalHost'. There is no registered service of type 'MatBlazor.IMatPortalService'.
Turns out 3.Add registration of service to Startup.cs
is not the same for Blazor WebAssembly App.
Add builder.Services.AddMatBlazor();
to Program.cs
Main
method in the BlazorWebAssemblyApp.Client
and then everything should work. No need to edit anything in BlazorWebAssemblyApp.Server
or BlazorWebAssemblyApp.Shared
.
Thanks, just what I needed as well for my Blazor WASM app!