Wrap and register your Angular Ivy Component as custom element
- Install dependencies
git clone https://github.com/aelbore/ngx-elements.git cd ngx-elements npm install
npm install ngx-elements
npm run ngcc
- compile all@angular/*
libraries into ivy compatiblenpm run build
- buildngx-elements
npm run build:profile
- build the example codenpm run serve
- run into browserhttp://localhost:5000
renderCustomElement
- wrap and register your component into custom element (web components)renderNgComponent
- wrap your component to automatically have change detection
- Constructable Stylesheets
- AutoChangeDetectChanges
- Register Multiple Components, Directives, and Pipes
renderCustomElement(HelloWorldComponent, { directives: [ NgForOf, MyTabItemComponent, MyTabComponent ], pipes: [ AsyncPipe ] })
- Create
hello-world.ts
- When you change the value of
<input>
it will trigger the change detection (detectChanges
) to update the<h1>
element - by default it will trigger the change dectection when any of the properties changed
import { Component, ViewEncapsulation, Input } from "@angular/core"; import { renderCustomElement } from 'ngx-elements' @Component({ selector: "hello-world", template: ` <h1>Hello {{ name }}</h1> <input [value]="name" (input)="updateName($event.target.value)" /> `, styles: [` h1 { color: var(--h1-color, blue) } `], encapsulation: ViewEncapsulation.ShadowDom }) export class HelloWorldComponent { @Input() name: string = "World" updateName(newName: string) { this.name = newName } } renderCustomElement(HelloWorldComponent)
- When you change the value of