ngx-lazy-elements
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

ngx-lazy-elements

Library that helps you manage lazy Angular Elements Web Components

Build Status

Installation

npm i --save ngx-lazy-elements

Dependencies

Using web components in production requires polyfills:

  • elements-zone-strategy
  • @angular/elements
  • document-register-element
  • @webcomponents/webcomponentsjs

For more information follow the guide here: https://blog.lvq.dk/complete-angular-elements-example/

Usage

For instance import in root app module and make sure to use .forRoot(). The service relies on a shared state, therefor it needs to be imported only once and be provided in 'root'.

Methods to look out for .startObservingDOM(), .registerImmediate() and .registerLazily().

In order to make sure your application runs smoothly, make sure to only use .registerImmediate() for components available at initial load. If you know that a component will be created dynamically, then use .registerLazily(), that will only register when a tag is present in DOM.

Example

import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { NgxLazyElementsModule, NgxLazyElementsService } from 'ngx-lazy-elements';
import { YourAwesomeComponent } from './your-awesome.component';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    NgxLazyElementsModule.forRoot();
  ],
  bootstrap: [AppComponent],
})
export class AppModule {
  constructor(public ngxLazyElementsService: NgxLazyElementsService) {
    ngxLazyElementsService.startObservingDOM();

    ngxLazyElementsService.registerImmediate('my-tag', YourAwesomeComponent);
    ngxLazyElementsService.registerLazily('my-other-tag', YourAwesomeComponent);
  }
}

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i ngx-lazy-elements

    Weekly Downloads

    12

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    318 kB

    Total Files

    60

    Last publish

    Collaborators

    • larsvonqualen