Skip to content

Commit f5d6103

Browse files
Fix usage of JSInterop
1 parent 22dbcc5 commit f5d6103

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

BlazorComponentSample/Component1.cshtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
@using Microsoft.AspNetCore.Components
22
@inherits ComponentBase
3+
@using Microsoft.JSInterop
4+
@inject IJSRuntime jSRuntime
35
<div class="my-component">
46
This Blazor component is defined in the <strong>BlazorComponentSample</strong> package.
57
</div>
@@ -10,6 +12,6 @@
1012
{
1113
Task OnClick(UIMouseEventArgs args)
1214
{
13-
return ExampleJsInterop.Prompt("you clicked me");
15+
return ExampleJsInterop.Prompt(jSRuntime,"you clicked me");
1416
}
1517
}

BlazorComponentSample/ExampleJsInterop.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
using Microsoft.AspNetCore.Components;
12
using Microsoft.JSInterop;
23
using System.Threading.Tasks;
34

45
namespace BlazorComponentSample
56
{
67
public class ExampleJsInterop
78
{
8-
public static Task<string> Prompt(string message)
9+
public static Task<string> Prompt(IJSRuntime jSRuntime, string message)
910
{
1011
// Implemented in exampleJsInterop.js
11-
return JSRuntime.Current.InvokeAsync<string>(
12+
return jSRuntime.InvokeAsync<string>(
1213
"exampleJsFunctions.showPrompt",
1314
message);
1415
}

0 commit comments

Comments
 (0)