Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@angular/elements

Package Overview
Dependencies
Maintainers
2
Versions
702
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@angular/elements

Angular - library for using Angular Components as Custom Elements

  • 19.1.0-next.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
296K
decreased by-5.17%
Maintainers
2
Weekly downloads
 
Created

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 26 Nov 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc