How to invoke a nested function

Posted 3 years ago by truthz03
Edited 3 years ago
0

Hi,

I love C# and therefore I'm trying to switch my Angular frontend to a Blazor WebAssemby frontend but not all of the used javascript libraries I'm using in my Angular frontend are available as C# library.

I tried many hours to get the first javascript lib working but without succes.

The first javascript lib I want to use is keycloak.js which contains methods like init, login and logout but I dont know how to call them. 

If I call "await JSRuntime.InvokeVoidAsync("Keycloak", new object[] { keycloakClientOptions });" I get into "function Keycloak (config)" but how can I than call init, login or logout?

 

Thanks

Thomas

  • 0

    I haven't worked with Keycloak, but generally speaking, if you want to invoke a specific JavaScript function, you'd do something like this:

    string txt = await jsRuntime.InvokeAsync<string>("methods.getText");

    This would return a string from a JavaScript file that looked something like:

    window.methods = {
        getText: function () {
            return "Some text";
        }
    };

    You can learn more about invoking JavaScript functions from Blazor at: https://docs.microsoft.com/en-us/aspnet/core/blazor/call-javascript-from-dotnet?view=aspnetcore-3.1

    Posted 3 years ago by selliott
Someone is typing...

Post a Reply

You must be logged in to add a new post.
Number of online users: 0
An error has occurred. This application may no longer respond until reloaded. Reload 🗙