npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ngx-loadable-component

v0.0.4

Published

Lazy load & code-split your Angular components.

Readme

ngx-loadable-component

Dynamically lazy load & code-split your Angular components.

(Supports Angular 6+)

Core functionality derived heavily from dynamically loading components with angular-cli

Easily 💤 lazy load & ⚡ code-split, components in 🅰 Angular

🚧 no mucking around with seperate build processes

💤 lazy load components

🆓 free code splitting via Angular

demo

🤓 ingenious core pattern thought up by actual smart people

👌 created for the use case of seperating large single components (such as wysiwg editors, charts .etc) from the rest of your app code.

Installation

Install via npm;

npm i ngx-loadable-component

Setup

Create a component you wish to dynamically load... e.g. loadable component

upside-down-face-emoji.component.ts

@Component({
  selector: 'app-upside-down-face-emoji'
  ...
})
export class UpsideDownFaceEmojiComponent { }

* its important that this component does not use OnPush changeDetection as this will interfere with the loadable component setup

Then create a module for the loadable component:

upside-down-face-emoji.module.ts

import { LoadableComponentModule } from 'ngx-loadable-component';

import { UpsideDownFaceEmojiComponent } from './upside-down-face-emoji.component';

@NgModule({
  imports: [
    // register as loadable component
    LoadableComponentModule.forChild(UpsideDownFaceEmojiComponent)
  ],
  declarations: [UpsideDownFaceEmojiComponent]
})
export class UpsideDownFaceEmojiComponentModule {}

Create a manifest file which lists all your loadable components:

app-loadable.manifests.ts

import { LoadableManifest } from 'ngx-loadable-component';

export enum LoadableComponentIds {
  UPSIDE_DOWN_FACE = 'UpsideDownFaceEmojiComponent'
}

export const appLoadableManifests: Array<LoadableManifest> = [
  {
    // used to retrieve the loadable component later
    componentId: LoadableComponentIds.UPSIDE_DOWN_FACE,
    // must be a unique value within the app...
    // but apart from that only used by angular when loading component
    path: `loadable-${LoadableComponentIds.UPSIDE_DOWN_FACE}`,
    // relative path to component module
    loadChildren: './components/upside-down-face-emoji/upside-down-face-emoji.module#UpsideDownFaceEmojiComponentModule'
  }
];

Add the loadable component manifest & loadable component module to root app module:

app.module.ts

import { LoadableComponentModule } from 'ngx-loadable-component';

// loadable components manifest
import { appLoadableManifests } from './app-loadable.manifests';

@NgModule({
  declarations: [
      ...
  ],
  imports: [
    ...
    // components to load as seperate async
    LoadableComponentModule.forRoot(appLoadableManifests)
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Be sure to import the loadable component module into any feature modules you use it in:

my-feature.module.ts

import { LoadableComponentModule } from 'ngx-loadable-component';

@NgModule({
  declarations: [
      ...
  ],
  imports: [
    ...
    LoadableComponentModule.forFeature()
  ]
})
export class MyFeatureModule { }

Usage (basic)

Add a loadable component where needed:

app.component.html

<div class="app--emojis">

    <loadable-component [componentId]="UPSIDE_DOWN_FACE_COMPONENT_ID" [loadComponent]="loadUpsideDownFaceComponent">
        <!-- any element in the loadable component content area will only be shown whilst loadComponent is false -->
        <app-placeholder-emoji></app-placeholder-emoji>
    </loadable-component>

</div>

app.component.ts

import { LoadableComponentIds } from '../../app-loadable.manifests';

@Component({ ... })
export class AppComponent {
  // loadable component ids
  UPSIDE_DOWN_FACE_COMPONENT_ID: string = LoadableComponentIds.UPSIDE_DOWN_FACE;

  // flags to load components
  // setting this to 'true' will cause the loadable component
  // to load the specified component id
  loadUpsideDownFaceComponent: boolean = false;
}

Usage (with Inputs/Outputs)

If our loadable component has inputs/outputs - like so:

upside-down-face-emoji.component.html

<a (click)="onClick()">
    <div>🙃</div>
    <div>{{ text }}</div>
</a>

upside-down-face-emoji.component.ts

export class UpsideDownFaceEmojiComponent {
  @Input() text: string = 'upside down';

  @Output() clicked: EventEmitter<string> = new EventEmitter<string>();

  constructor() {}

  onClick(): void {
    this.clicked.emit(this.text);
  }
}

We then create a model representing the inputs/outputs (for some typing goodness 💯):

upside-down-face-emoji.inputs.model.ts

import { LoadableComponentInputs } from 'ngx-loadable-component';

export interface UpsideDownFaceEmojiComponentInputs extends LoadableComponentInputs {
  text: string;
}

upside-down-face-emoji.outputs.model.ts

import { LoadableComponentOutputs } from 'ngx-loadable-component';

export interface UpsideDownFaceEmojiComponentOutputs extends LoadableComponentOutputs {
  clicked: Function;
}

And add our inputs/outputs to the loadable component wherever its used:

app.component.html

<div class="app--emojis">

    <loadable-component
        [componentId]="UPSIDE_DOWN_FACE_COMPONENT_ID"
        [loadComponent]="loadUpsideDownFaceComponent"
        [componentInputs]="upsideDownFaceInputs"
        [componentOutputs]="upsideDownFaceOutputs">
        <!-- any element in the loadable component content area will only be shown whilst loadComponent is false -->
        <app-placeholder-emoji></app-placeholder-emoji>
    </loadable-component>

</div>

app.component.ts

import { LoadableComponentIds } from '../../app-loadable.manifests';
import { UpsideDownFaceEmojiComponentInputs } from '../../components/upside-down-face-emoji/models/upside-down-face-emoji.inputs.model';
import { UpsideDownFaceEmojiComponentOutputs } from '../../components/upside-down-face-emoji/models/upside-down-face-emoji.outputs.model';

@Component({ ... })
export class AppComponent {
  // loadable component ids
  UPSIDE_DOWN_FACE_COMPONENT_ID: string = LoadableComponentIds.UPSIDE_DOWN_FACE;

  // flags to load components
  // setting this to 'true' will cause the loadable component
  // to load the specified component id
  loadUpsideDownFaceComponent: boolean = false;

  // inputs for loadable component
  get upsideDownFaceInputs(): UpsideDownFaceEmojiComponentInputs {
    return {
      text: 'not upside down'
    }
  }

  // outputs for loadable component
  get upsideDownFaceOutputs(): UpsideDownFaceEmojiComponentOutputs {
    return {
      clicked: (text: string) => this.onClickedUpsideDownFace(text)
    }
  }

  onClickedUpsideDownFace(text: string): void {
    console.log('🖱', text);
  }
}

And voila! we now have input/output binding 👌. * note that the inputs in the parent component (of the loadable component - e.g. upsideDownFaceInputs()) have to be within a getter or function for change detection to apply correctly

Usage (add custom css classes)

Custom css classes can be passed via the loadable component componentCssClasses input. These will be added to the host element of the provided loadable component. e.g.

app.component.html

<div class="app--emojis">

    <loadable-component ... [componentCssClasses]="customCssClasses" >
        ...
    </loadable-component>

</div>

app.component.ts

@Component({ ... })
export class AppComponent {
  ...
  // custom css classes
  customCssClasses: Array<string> = ['my-custom--class--1', 'my-custom--class--2']
  ...
}

Author

🤔 created by Dan Harris

👨‍💻 website: danharris.io

🐤 twitter: @danharris_io

☕ made with love and late nights

🤷‍ this package works well for my use case... no guarantees made to its general use

Odds & Ends

👀 MIT License

💖 if you've read this far... thanks for the star

😎 title font courtesy of the awesome lazer84 font

😡 please send all abusive letters via handwritten note to this address

📫 all constructive feedback welcome.