Skip to content

asathkumara/blazor-jsinterop-helpers

Repository files navigation

Readme-Banner-1200x300

Nuget (with prereleases) Nuget

Table of Contents

  1. Overview
  2. Installation
  3. Usage
  4. Documentation
  5. License

Overview

When building robust and complex razor components using Blazor, interactions with the Document Object Model (DOM) become inevitable.

This package extends the JavaScript (JS) interoperability in Blazor through helpers for interacting with the DOM's Window and Element APIs.

Installation

Package Manager

Install-Package Blazor.JSInterop.Handlers -Version 1.1.1

.NET CLI

dotnet add package Blazor.JSInterop.Handlers

PackageReference

<PackageReference Include="Blazor.JSInterop.Handlers" Version="1.1.1">

Usage

To use the package, you first need to configure your dependency injection (DI) container. Add the following line of code to your Program.cs:

builder.Services.AddBlazorInteropHandlers();

Then add references to the namespaces in your _Imports.razor or as directives at the top of your razor component's page:

@using Blazor.JSInterop.Helpers.Services
@using Blazor.JSInterop.Helpers.Models

Finally, inject instances of the service as needed in your razor component in your directive section or code section:

// In directive section
@inject IElementHandler elementHandler
@inject IWindowHandler windowHandler

// In code section
@code
{
    [Inject] IElementHandler elementHandler;
    [Inject] IWindowHandler windowHandler;
}

Documentation

View complete API documentation and examples on the wiki

License

This project is licensed under MIT. Feel free to re-use any libraries or code for non-commercial use but do your due diligence with attributing credit.

About

A NuGet package that extends the JavaScript interoperability in Blazor through helpers for interacting with the DOM's Window and Element APIs.

Topics

Resources

License

Stars

Watchers

Forks