Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@juristr/ngx-lazy-el
Advanced tools
[![npm version](https://badge.fury.io/js/%40juristr%2Fngx-lazy-el.svg)](https://badge.fury.io/js/%40juristr%2Fngx-lazy-el)
Easy lazy loading components 💪 by Angular Elements.
Important note: for now this is an experiment and still needs to be battle-tested. API might break! Meanwhile, follow me @juristr) for questions/ideas/getting notified about updates.
This library depends on Angular Elements. You can install that via
$ ng add @angular/elements
Install the library from npm.
$ npm install @juristr/ngx-lazy-el
or
$ yarn add @juristr/ngx-lazy-el
First of all, expose the Angular Component that should be loaded via a customElementComponent
property.
...
@NgModule({
declarations: [HelloWorldComponent],
...
exports: [HelloWorldComponent]
})
export class HelloWorldModule {
customElementComponent: Type<any> = HelloWorldComponent;
}
Just like with the Angular Router, define the map of component selector and lazy module.
// app.module.ts
...
const lazyConfig = [
{
selector: 'app-hello-world',
loadChildren: () =>
import('./hello-world/hello-world.module').then(m => m.HelloWorldModule)
}
];
@NgModule({
...
imports: [
...
NgxLazyElModule.forRoot(lazyConfig),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
To use the lazy loaded component in another module, first of all register the CUSTOM_ELEMENT_SCHEMA
.
import { ..., CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
...
})
export class SomeModule {}
That is needed because otherwise Angular won't recognize the tag as it is no more an Angular Component, but Custom Element.
Next, you can just use the Custom Element by applying the *ngxLazyEl
directive.
<app-hello-world *ngxLazyEl [person]="person"></app-hello-world>
If it is behind a *ngIf
or other non-visible component, the app-hello-world
will be lazy loaded on the fly.
Open an issue or ping me on Twitter.
FAQs
[![npm version](https://badge.fury.io/js/%40juristr%2Fngx-lazy-el.svg)](https://badge.fury.io/js/%40juristr%2Fngx-lazy-el)
We found that @juristr/ngx-lazy-el demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.