1.1.0 • Published 3 years ago

ngx-lazy-elements v1.1.0

Weekly downloads
21
License
MIT
Repository
github
Last release
3 years ago

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);
  }
}
1.1.0

3 years ago

1.0.9

3 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago

0.0.0

5 years ago