You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/components/js-spa-frameworks.md
+30-17Lines changed: 30 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,16 +20,27 @@ This article covers how to render Razor components from JavaScript, use Blazor c
20
20
<!-- UPDATE 11.0 - The `blazor.web.js` (Blazor Web App) portions of
21
21
this article have been commented out for the time being to
22
22
facilitate reconstituting the guidance later when support lands.
23
-
It was under consideration for .NET 10 on
24
-
https://github.com/dotnet/AspNetCore.Docs/issues/35653, but
25
-
it didn't make the cut and was backlogged. -->
23
+
The PU work is tracked by https://github.com/dotnet/aspnetcore/issues/53920. -->
26
24
27
25
## Angular sample apps
28
26
29
-
<!-- UPDATE 10.0 Add migration instructions for 9.0 to 10.0 -->
27
+
The following sample apps demonstrate rendering a Razor component as a [Blazor custom element](#blazor-custom-elements) in an Angular app:
30
28
31
-
*[CustomElementsBlazorSample (Blazor Server) (`javiercn/CustomElementsBlazorSample`, branch: `blazor-server`)](https://github.com/javiercn/CustomElementsBlazorSample/tree/blazor-server): Blazor Server is supported in .NET 8/9. To migrate this .NET 7 sample, see <xref:migration/70-to-80#update-a-blazor-server-app> and <xref:migration/80-to-90>.
32
-
*[CustomElementsBlazorSample (Blazor WebAssembly) (`javiercn/CustomElementsBlazorSample`, branch: `blazor-wasm`)](https://github.com/javiercn/CustomElementsBlazorSample/tree/blazor-wasm): To migrate this .NET 7 sample, see <xref:migration/70-to-80#update-a-blazor-webassembly-app> and <xref:migration/80-to-90>.
Take the following steps to register a root component as a custom element in a Blazor WebAssembly app.
344
-
345
-
Add the <xref:Microsoft.AspNetCore.Components.Web?displayProperty=fullName> namespace to the top of the `Program` file:
346
-
347
-
```csharp
348
-
usingMicrosoft.AspNetCore.Components.Web;
349
-
```
354
+
Register a root component as a custom element in a Blazor WebAssembly app. In the following example, the code:
350
355
351
-
Add a namespace for the app's components. In the following example, the app's namespace is `BlazorSample` and the components are located in the `Pages` folder:
356
+
* Adds a namespace for the app's components. In the example, the app's namespace is `BlazorSample`, and the components are located in the `Pages` folder.
357
+
* Provides access to the API in the <xref:Microsoft.AspNetCore.Components.Web?displayProperty=fullName> namespace.
358
+
* Calls <xref:Microsoft.AspNetCore.Components.Web.CustomElementsJSComponentConfigurationExtensions.RegisterCustomElement%2A> on <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder.RootComponents> to register the `Counter` component with the custom HTML element `my-counter`.
Call <xref:Microsoft.AspNetCore.Components.Web.CustomElementsJSComponentConfigurationExtensions.RegisterCustomElement%2A> on <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder.RootComponents>. The following example registers the `Counter` component with the custom HTML element `my-counter`:
@@ -475,3 +484,7 @@ Generate JavaScript (JS) components from Razor components for JavaScript technol
475
484
476
485
> [!WARNING]
477
486
> The Angular and React component features are currently **experimental, unsupported, and subject to change or be removed at any time**. We welcome your feedback on how well this particular approach meets your requirements.
0 commit comments