Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSRuntime is not registered Blazor

I have a Blazor Wasm project and when I want to inject the JSRuntime

@inject JSRuntime js

I'm getting this error: "Cannot provide a value for property 'js' on type 'BlazorApp.Pages.Page'. There is no registered service of type 'Microsoft.JSInterop.JSRuntime'"

Is JSRuntime not registered by default? How do I register it?

Thanks

like image 252
SamBerk Avatar asked Sep 04 '20 15:09

SamBerk


2 Answers

You need to inject IJSRuntime, not JSRuntime.

like image 67
Lex Avatar answered Oct 20 '22 20:10

Lex


Try

@inject IJSRuntime JSRuntime

and in method use JSRuntime as object with methods.

like image 33
Vlad Terentev Avatar answered Oct 20 '22 20:10

Vlad Terentev