Razor.Clipboard icon indicating copy to clipboard operation
Razor.Clipboard copied to clipboard

Can clipbnoard be used without lambda function?

Open andy-burns-uk opened this issue 2 years ago • 0 comments

In a blazor server app I've tried to use a "normal" function to access the clipboard, instead of the lambda function per your example

@page "/Clipboard" @using CurrieTechnologies.Razor.Clipboard @inject ClipboardService clipboard

<PageTitle>cliptest</PageTitle> <button @onclick="myfunc">myfunc

@code private async void myfunc(MouseEventArgs e) { string a = await clipboard.ReadTextAsync(); }

your minified js is included in the page via the _host.cshtml but I get an exception when I click my button

Exception has occurred: CLR/Microsoft.JSInterop.JSException Exception thrown: 'Microsoft.JSInterop.JSException' in System.Private.CoreLib.dll: 'Document is not focused. undefined' at System.Threading.Tasks.ValueTask1.get_Result() at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__161.MoveNext() at System.Threading.Tasks.ValueTask`1.get_Result() at CurrieTechnologies.Razor.Clipboard.ClipboardService.<ReadTextAsync>d__4.MoveNext() at blazorWeb.Pages.Clipboard.d__2.MoveNext() in C:\Data\Dev\MDTinfo3\blazorWeb\Pages\Clipboard.razor:line 32

Is this "document not focused" the reason you had to use a lambda function, or should my code work?

andy-burns-uk avatar Jan 24 '23 15:01 andy-burns-uk