🚀 Socket Launch Week 🚀 Day 4: Introducing Historical Analytics.Learn More

@angular/elements

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
a

@angular/elements

Angular - library for using Angular Components as Custom Elements

19.2.8
latest
100

Supply Chain Security

100

Vulnerability

70

Quality

97

Maintenance

100

License

Version published
Weekly downloads
246K
-33.29%
Maintainers
2
Weekly downloads
 
Created
Issues
1586

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

FAQs

Package last updated on 23 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts