mcpField
A
angular-elements

angular-elements

github.com/oguzhan18Development7188 installsUpdated 31w ago
Repository

About angular-elements

A development skill for turning Angular components into custom elements with @angular/elements. It covers input and output mapping, standalone elements, packaging, and use in micro-frontends.

Key features

  1. 01Create custom elements from Angular components
  2. 02Map component inputs and outputs
  3. 03Configure custom element behavior
  4. 04Build standalone elements
  5. 05Bundle elements for distribution
  6. 06Register elements for micro-frontends

Use cases

  1. 01Expose an Angular component as a web component
  2. 02Connect web component attributes and events to Angular
  3. 03Build reusable elements for micro-frontends
  4. 04Configure a single-bundle element build

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/oguzhan18/angular-ecosystem-skills --skill angular-elements

After installing, type/angular-elementsin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/discussions/
_INDEX.md
references/docs/
_INDEX.md
references/issues/
_INDEX.md
references/releases/
_INDEX.md

Details

From the project README

@angular/elements

Version: Angular 21 (2025) Tags: Web Components, Custom Elements, Micro-frontends

References: Elements Guide • API

API Changes

This section documents recent version-specific API changes.

  • NEW: createCustomElement API — Package Angular components as custom elements

  • NEW: NgElementConfig — Configure custom element behavior

  • NEW: Input/Output mapping — Map Angular inputs/outputs to web component attributes

  • NEW: Standalone elements — Build standalone elements without NgModule

Best Practices

  • Install @angular/elements
npm install @angular/elements
  • Create custom element from component
import { createCustomElement } from '@angular/elements';

@Injectable()
export class ElementRegistrar {
  constructor(private injector: Injector) {}

  register() {
    const element = createCustomElement(MyComponent, { injector: this.injector });
    customElements.define('my-element', element);
  }
}
  • Use in main.ts
import { createApplication } from '@angular/platform-browser';
import { createCustomElement } from '@angular/elements';

bootstrapApplication(AppComponent).then(appRef => {
  const element = createCustomElement(MyComponent, { injector: appRef.injector });
  customElements.define('my-component', element);
});
  • Map inputs and outputs
const element = createCustomElement(MyComponent, {
  injector: this.injector,
  events: ['myEvent'],
  attributes: ['myInput']
});
  • Use CUSTOM_ELEMENTS_SCHEMA
// To use custom elements in Angular
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';

@NgModule({
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule {}
  • Build as web component
// angular.json
{
  "build": {
    "options": {
      "outputPath": "dist",
      "singleBundle": true
    }
  }
}
  • Use input() and output() for web component data
@Component({
  selector: 'my-element',
  standalone: true
})
export class MyElementComponent {
  data = input<string>('');
  output = output<string>();

  onClick() {
    this.output.emit('event-data');
  }
}
  • Handle content projection
@Component({
  selector: 'my-element',
  template: `
    <div class="header">
      <ng-content select="[header]"></ng-content>
    </div>
    <div class="body">
      <ng-content></ng-content>
    </div>
  `
})
export class MyElementComponent {}
  • Use for micro-frontends
// Register multiple elements
const elements = [ButtonComponent, CardComponent, InputComponent];
elements.forEach(comp => {
  const el = createCustomElement(comp, { injector });
  customElements.define(comp.selector, el);
});

Comments

Markdown supported