This repository showcases the integration of a Blazor WebAssembly Library project used as a Web-Component in the Angular App
This project is maintained by JayLathiaTR
| Tool | Version |
|---|---|
| VS Code | Latest |
| Visual Studio 2022 | Latest |
| Angular CLI | 18.2.3 |
| Node | 20.17.0 |
| Package Manager | npm 10.8.3 |
dotnet new razorclasslib -o CommentboxComponentLibraryCommentboxComponent with the name of your component.Open the Library project in Visual Studio 2022 and rename _Component1.razor to CommentboxComponent.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.
\bin\Release\net8.0.
TR.BlazorWasmWebComponent solution 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.
Program.cs and register the Library component as a CustomElement for Angular:
builder.RootComponents.RegisterCustomElement<CommentboxComponent>("commentbox-component");Open _Imports.razor and add the component’s using directive.
Open App.razor and 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).
Program.cs again. (as we are not using this project as a self-hosted app)Right-click the project and select Publish.
wwwroot directory. Copy the folders _content and _framework.
Navigate to the src/assets directory of the TR.AngularBlazorClient project and paste the copied Blazor published folders.
Program.cs with CustomElement.
Update the route to navigate to your component in app.routes.ts.
ng buildng serve -oCreate 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:
StepCount becomes step-count in Angular).SetDetails becomes setDetails in Angular).ParentComponentLibrary and ChildComponentLibrary.SharedModelLibrary & ChildComponentLibrary.SharedModelLibrary.ParentComponentLibrary is required for Angular consumption. ChildComponentLibrary registration is optional, if it is not directly consumed in Angular.