include entire Javascript module into Blazor Server

403 views Asked by At

I'm pretty new to web programming and blazor. I found an open source form designer on github that is written in javascript. See here: https://github.com/Draggable/formeo I would like to embed this designer in a blazor server web application. Do you think this is possible and do you have any advice on how to do it?

1

There are 1 answers

2
Henrique Pombo On

You can create a js file, let's call it site.js:

In your _host.cshtml you can insert the tag:

<script src="js/site.js"></script>

After that, in a component you can use

@using Microsoft.JSInterop      @*This can go in your _Imports.razor so it will apply to the whole project*@
@inject IJSRuntime JSRuntime;   @*Dependency Injection*@
.
.
.
@code {
    private async Task myFunction(){
        await JSRuntime.InvokeVoidAsync("myFunctionName", myFunctionParameters);
    }
}