How did you get this to compile?
this is a great idea but going from static to instanced variables seems like a stretch
namespace MyLib { public static class MyLibElementRefExtensions { private readonly IJSRuntime _jsRuntime;
public MyJsInterop(IJSRuntime jsRuntime)
{
_jsRuntime = jsRuntime;
}
public static Task Focus(this ElementRef elementRef)
{
return _jsRuntime.InvokeAsync<object>(
"myLib.focusElement", elementRef);
}
}
}
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 93f4eeb7-4bf9-2631-3814-52bd4608445b
- Version Independent ID: fcde7f10-d897-1276-a3b7-4c5d19d14e4c
- Content: Razor Components JavaScript interop
- Content Source: aspnetcore/razor-components/javascript-interop.md
- Product: aspnet-core
- GitHub Login: @guardrex
- Microsoft Alias: riande
Hello @pfeurean ... See the Announcement, and there's a linked discussion issue.
- https://github.com/aspnet/Announcements/issues/347
- https://github.com/aspnet/AspNetCore/issues/6828 (crosslinked from the Announcement)
his topic will receive another round of updates by the end of March ... Keep an :eye: out for new content. We update the topic's date when we make changes.
I'm still somewhat confused by this. How does a static class have an instance member and a nonstatic constructor? @guardrex neither link addresses this: the first discusses cshtml files and the second mentions [Inject], which doesn't occur in the example (which is explicitly called ElementRefExtensions.cs).
@dharmaturtle Thanks for letting me know ... it probably requires an update. The changes for Preview3 were performed in a rush before I stepped onto a plane to fly out of here, and we couldn't get engineering reviews at that time. I just returned. Engineering should be reviewing it soon, too. They're also just getting settled back into a normal workflow now that Preview3 and the MVP Summit are behind us.
I'll ping u on the PR for the next round of updates to the topic. I'm going to work that next, so you should get a ping sometime today. If another round of updates doesn't help, you can ask the engineers directly on the discussion issue attached to the Announcement.
btw --- I like the avatar! :smile: :+1: