This repository showcases the integration of a Blazor WebAssembly Library project used as a Web-Component in the Angular App
- Pre-requisites
- Create New Blazor Library for a Specific Component
- Integrate Library Component into TR.BlazorWasmWebComponent
- Integrate Angular App with Blazor Published Components
- Using BlazorComponents with Attributes
- Parent-Child component approach
| Tool | Version |
|---|---|
| VS Code | Latest |
| Visual Studio 2022 | Latest |
| Angular CLI | 18.2.3 |
| Node | 20.17.0 |
| Package Manager | npm 10.8.3 |
-
Navigate to the TR.BlazorComponentLibraries directory in the command line and run the following command:
dotnet new razorclasslib -o CommentboxComponentLibrary- Replace
CommentboxComponentwith the name of your component.
-
Open the Library project in Visual Studio 2022 and rename
_Component1.razortoCommentboxComponent.razor.
-
Add your page route, div, style, and code for this Razor component. Ensure the page route is unique.

-
Save your Razor page and build the solution in Release mode.

-
This will generate the DLL and other binaries at
\bin\Release\net8.0.
-
Open the
TR.BlazorWasmWebComponentsolution in Visual Studio 2022. -
Right-click on the project and select Add Project Reference.

-
Browse to your newly created component library DLL and click OK.

-
Open
Program.csand register the Library component as a CustomElement for Angular: -
Open
_Imports.razorand add the component's using directive.
-
Open
App.razorand add this component as an AdditionalAssemblies under Router.
-
Build and run the project, navigate to the page's route (e.g.,
https://localhost:7105/commentbox).
-
Close the browser and comment out lines 12, 13, 14 of
Program.csagain. (as we are not using this project as a self-hosted app) -
Click the Publish button in the Publish window.
-
After publishing, go to the published location and navigate to the
wwwrootdirectory. Copy the folders_contentand_framework.
-
Navigate to the
src/assetsdirectory of theTR.AngularBlazorClientproject and paste the copied Blazor published folders.
-
Open the code in VS Code editor and add the Blazor component in the Angular app.
-
Update the route to navigate to your component in
app.routes.ts.
-
Run the following commands:
ng buildng serve -o- App will be accessible at localhost:4200.

-
Navigate to your Angular route for your Blazor component to see it in action.

-
Create a Razor page with a property or a complex object decorated with
[Parameter].
-
From Angular, pass the attributes directly bound to the component or bind the complex object with the help of JS query selector.

Note:
- For an attribute binding directly to HTML, use kebab casing (e.g., Blazor
StepCountbecomesstep-countin Angular). - For a complex object binding via JS query selector, use camel casing (e.g., Blazor
SetDetailsbecomessetDetailsin Angular).
- SharedModelLibrary: Class library containing the models & items which are shared between
ParentComponentLibraryandChildComponentLibrary. - ParentComponentLibrary: References
SharedModelLibrary&ChildComponentLibrary. - ChildComponentLibrary: References
SharedModelLibrary. - Main Blazor WASM: References all three libraries.
- CustomElementRegistration: Custom element registration of
ParentComponentLibraryis required for Angular consumption.ChildComponentLibraryregistration is optional, if it is not directly consumed in Angular.


