Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/aelbore/ngx-elements

Wrap and register your Angular Ivy Component as custom element
https://github.com/aelbore/ngx-elements

angular customelements elements ivy rollup webcomponents

Last synced: 16 days ago
JSON representation

Wrap and register your Angular Ivy Component as custom element

Awesome Lists containing this project

README

        

[![npm version](https://badge.fury.io/js/ngx-elements.svg)](https://www.npmjs.com/package/ngx-elements)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)

# ngx-elements
Wrap and register your Angular Ivy Component as custom element

Getting Started
------------
* Install dependencies
```
git clone https://github.com/aelbore/ngx-elements.git
cd ngx-elements
npm install
```

Installation
------------
```
npm install ngx-elements
```

Example
------------
* `npm run ngcc` - compile all `@angular/*` libraries into ivy compatible
* `npm run build` - build `ngx-elements`
* `npm run build:profile` - build the example code
* `npm run serve` - run into browser `http://localhost:5000`

API
-----
* `renderCustomElement` - wrap and register your component into custom element (web components)
* `renderNgComponent` - wrap your component to automatically have change detection

Features
-----
* [Constructable Stylesheets](https://developers.google.com/web/updates/2019/02/constructable-stylesheets)
* AutoChangeDetectChanges
* Register Multiple Components, Directives, and Pipes
```typescript
renderCustomElement(HelloWorldComponent, {
directives: [ NgForOf, MyTabItemComponent, MyTabComponent ],
pipes: [ AsyncPipe ]
})
```

Usage
-----
* Create `hello-world.ts`
- When you change the value of `` it will trigger the change detection (`detectChanges`) to update the `

` element
- by default it will trigger the change dectection when any of the properties changed
```typescript
import { Component, ViewEncapsulation, Input } from "@angular/core";
import { renderCustomElement } from 'ngx-elements'

@Component({
selector: "hello-world",
template: `

Hello {{ name }}



`,
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)
```