What is @angular/elements?
@angular/elements allows Angular components to be used as custom elements (web components). This enables the integration of Angular components into non-Angular applications and enhances reusability across different frameworks and libraries.
What are @angular/elements's main functionalities?
Creating a Custom Element
This code demonstrates how to create a custom element from an Angular component. The `createCustomElement` function is used to convert `MyComponent` into a custom element named 'my-element'.
import { Injector, NgModule } from '@angular/core';
import { createCustomElement } from '@angular/elements';
import { BrowserModule } from '@angular/platform-browser';
import { MyComponent } from './my-component.component';
@NgModule({
declarations: [MyComponent],
imports: [BrowserModule],
entryComponents: [MyComponent]
})
export class AppModule {
constructor(private injector: Injector) {
const myElement = createCustomElement(MyComponent, { injector });
customElements.define('my-element', myElement);
}
ngDoBootstrap() {}
}
Using the Custom Element in HTML
Once the Angular component is converted into a custom element, it can be used in any HTML file just like a standard HTML element. This example shows how to include and use the custom element 'my-element' in an HTML file.
<!DOCTYPE html>
<html>
<head>
<title>Angular Element</title>
<script src="path/to/your/angular-element.js"></script>
</head>
<body>
<my-element></my-element>
</body>
</html>
Other packages similar to @angular/elements
stencil
Stencil is a compiler that generates Web Components (custom elements) and builds high-performance web apps. It is framework-agnostic and can be used to create reusable components that work with any major framework or no framework at all. Compared to @angular/elements, Stencil is more focused on performance and offers additional features like lazy loading and pre-rendering.
lit
Lit is a simple library for building fast, lightweight web components. It provides a minimal API to define custom elements and manage their lifecycle. Lit is known for its small size and ease of use, making it a good alternative to @angular/elements for projects that require lightweight and fast custom elements.
vue-custom-element
vue-custom-element is a Vue plugin that enables the creation of custom elements from Vue components. It allows Vue components to be used as web components in non-Vue applications. This package is similar to @angular/elements but is tailored for Vue.js, providing a seamless way to integrate Vue components as custom elements.
Angular
The sources for this package are in the main Angular repo. Please file issues and pull requests against that repo.
Usage information and reference details can be found in Angular documentation.
License: MIT
20.0.0-rc.2 (2025-05-21)
Deprecations
platform-browser
- All entries of the
@angular/platform-browser-dynamic
Breaking Changes
core
Resource.value()
now returns a default value when in a loading state after reloading the error state
Resource.value()
now throws an error when it's in an error state. Previously it returned undefined
.
Resource.error
now has a type of Signal<Error | undefined>
instead of Signal<unknown>
Resource.reload
has been moved to WritableResource.reload
.
common
| Commit | Type | Description |
| -- | -- | -- |
| af7881abac | fix | cancel reader when app is destroyed (#61528) |
| 966df84351 | fix | prevent reading chunks if app is destroyed (#61354) |
compiler
| Commit | Type | Description |
| -- | -- | -- |
| e74266b108 | fix | avoid conflicts between HMR code and local symbols (#61550) |
compiler-cli
| Commit | Type | Description |
| -- | -- | -- |
| b57084267e | fix | Always retain prior results for all files (#61487) |
| 7a3a41f33f | fix | avoid ECMAScript private field metadata emit (#61227) |
core
| Commit | Type | Description |
| -- | -- | -- |
| 7efb3384a7 | fix | cleanup rxResource
abort listener (#58306) |
| b90160d10a | fix | cleanup testability subscriptions (#61261) |
| 3ba39bc28f | fix | getting resource value throws an error instead of returning undefined (#61441) |
| ca6295e90b | fix | handle different DI token types in Chrome DevTools integration (#61333) |
| d62379bb13 | fix | move reload method from Resource to WritableResource (#61441) |
| a89f1cff24 | fix | narrow error type for resources API (#61441) |
| 6e79eaf739 | fix | reading resource value after reload in the error state (#61441) |
| 350776b412 | fix | TestBed.tick should ensure test components are synchronized (#61382) |
| 648d42fe65 | fix | Testing should not throw when Zone does not patch test FW APIs (#61376) |
| 5dbeb42308 | fix | unregister onDestroy
in toSignal
. (#61514) |
| 30e081287d | fix | update min Node.js support to 20.19, 22.12, and 24.0 (#61500) |
platform-browser
| Commit | Type | Description |
| -- | -- | -- |
| bc2cab747f | refactor | Deprecate the platform-browser-dynamic
package (#61043) |
platform-server
| Commit | Type | Description |
| -- | -- | -- |
| 6d8e57d131 | perf | speed up resolution of base (#61392) |
<!-- CHANGELOG SPLIT MARKER -->
<a name="19.2.12"></a>