The easiest way to lazy-load Angular Elements or any other web components in your Angular application!
by @tomastrajan
- Install
npm i @angular-extensions/elements
- Add
import { LazyElementsModule } from '@angular-extensions/elements';
- Append
LazyElementsModule
to theimports: []
of yourAppModule
- Add new
schemas: []
property withCUSTOM_ELEMENTS_SCHEMA
value to@NgModule
decorator of yourAppModule
- Use
*axLazyElement
directive on an element you wish to load and pass in the url of the element bundle
Example of module implementation...
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { LazyElementsModule } from '@angular-extensions/elements';
@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [BrowserModule, LazyElementsModule],
declarations: [AppComponent, FeatureComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
Example of component implementation
import { Component } from '@angular/core';
@Component({
selector: 'your-org-feature',
template: `
<some-element *axLazyElement="elementUrl"></some-element>
`
})
export class FeatureComponent {
elementUrl = 'https://your-org.com/elements/some-element.js';
}
Library was tested with the following versions of Angular and is meant to be used
with the corresponding major version ("@angular/core"": "^8.0.0"
with "@angular-extensions/elements": "^8.0.0"
).
-
7.x
-
8.x
Please, feel free to open an issue or submit a pull request to make this project better for everyone! 🤗
Tomas Trajan 💻 🎨 💡 📖 🤔 🚇 |
Wayne Maurer 🐛 💻 |
Santosh Yadav 💻 📦 |
David Dal Busco 💻 💡 |
Zama Khan Mohammed 💻 🤔 |
Angel Fraga Parodi 💡 🤔 |
---|