Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

How to Use Angular Components as Custom Elements

Angular Elements turns an Angular component into a browser custom element with input properties, attributes, and DOM Custom Events.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Angular Elements when you want an Angular component to behave like a browser custom element that can be inserted into ordinary HTML or another framework. Install @angular/elements, create a constructor with createCustomElement(), and register it with customElements.define(). Component inputs become attributes or properties, while outputs become DOM Custom Events.

How Angular Elements work

Angular Elements packages Angular components as custom elements—also called Web Components—using the browser’s custom-element mechanism. The browser’s CustomElementRegistry associates a tag name with its constructor; Angular’s @angular/elements package bridges the component interface and Angular change detection to that DOM API. Angular documents createCustomElement() as stable. It returns an NgElementConstructor based on the component and configuration, whose injector is the default injector for instances. See the Angular Elements guide and the createCustomElement API reference.

Register a component as a custom element

  1. Install @angular/elements with the package manager your Angular project uses.

  2. Import createCustomElement from @angular/elements, then create a constructor from your component and an injector configuration.

    What’s actually slowing this PC down?

    Pick the symptom - the matching free tool is one click away.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. Register the constructor with the browser, for example: customElements.define('app-greeting-element', GreetingComponentElement).

  4. Use the registered tag in the DOM and communicate with it using attributes or properties for inputs and DOM events for outputs.

Choose a tag name that is different from the Angular component’s selector. Angular warns that reusing the selector can cause Angular to create both a regular component instance and a custom-element instance on the same DOM element.

Pass inputs and listen for outputs

Inputs: attributes and properties

Angular exposes component inputs as properties on the custom element and maps them to HTML attributes. Since HTML attribute names do not preserve case distinctions, Angular converts input names to dash-separated lowercase. For example, an input alias named myInputProp is exposed as the attribute my-input-prop. Use the public input name or alias as the element’s data contract.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Outputs: Custom Events

Each component output is emitted as an HTML Custom Event. The event name is the output name or its alias, and the value emitted by the component is available as event.detail. That lets a non-Angular host listen with ordinary DOM event handling:

element.addEventListener('valueChanged', event => {
  console.log(event.detail);
});

Replace valueChanged with the output’s public name or alias. The event detail contains the value emitted by that output.

Use a custom element in an Angular template

Angular’s template checker reports unknown elements by default. For a custom element in an Angular template, add CUSTOM_ELEMENTS_SCHEMA to the relevant schema metadata. A standalone component can declare it in its schemas property; NgModule-based applications can declare it in the module metadata. The schema permits non-Angular dash-case elements and dash-case properties. See the component configuration guide and CUSTOM_ELEMENTS_SCHEMA API reference.

NO_ERRORS_SCHEMA is broader: it permits any element and any property. It is not interchangeable with the specific custom-element allowance; see the NO_ERRORS_SCHEMA API reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Type custom elements in TypeScript

Generic DOM APIs do not infer the component-specific properties of an arbitrary custom tag. Angular documents two ways to supply that type information:

  • Cast a result to NgElement & WithProperties<{...}>, describing the custom element’s input properties.

  • Augment HTMLElementTagNameMap for the registered tag so DOM methods can infer its element type.

These options provide TypeScript with the element shape; registration with customElements.define() still establishes the tag at runtime.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Angular Elements or dynamic component creation?

Choose based on the interface your host needs. Angular Elements is suited to a reusable DOM tag with attributes, properties, and events. Programmatic createComponent() is suited to Angular-managed dynamic construction when a registered, reusable custom tag is not the goal.

Consideration Angular Elements Dynamic createComponent()
Integration surface A browser custom-element tag, DOM properties, and Custom Events. An Angular component reference and application-managed view.
Lifecycle work Angular Elements integrates the component with the custom element’s DOM connection lifecycle. The application handles view attachment and cleanup.
Data flow HTML attributes or element properties for inputs; DOM events for outputs. Set component inputs and subscribe to outputs through Angular APIs.
Angular templates Use an appropriate schema to allow the custom tag in template validation. Construct the component within Angular rather than relying on a custom tag.

With dynamic creation, the documented workflow includes providing an EnvironmentInjector, attaching the host view to ApplicationRef so it participates in change detection, setting inputs, subscribing to outputs, and detaching or cleaning up the view. Angular Elements automates that integration when the desired interface is a DOM element. See the createComponent API reference.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.