@gernsdorfer/async-component-loader
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Async Component Loader

A small Angular Library to load standalone components asynchronously

Test, Lint, Build Publish to NPM styled with PRs coverage async-component-loader


UI Demo

Open in StackBlitz

Install

Yarn

yarn add @gernsdorfer/async-component-loader

NPM

npm install @gernsdorfer/async-component-loader

Usage

  1. import the AsyncComponentLoaderComponent into your module or component
import {AsyncComponentLoaderComponent, LazyComponentCreator} from "@gernsdorfer/async-component-loader";

@NgModule({
  // ...
  imports: [AsyncComponentLoaderComponent],
  // ...
})
@Component({
  selector: 'my-component',
  template: `
   <async-component-loader 
                  [lazyComponentCreator]="counterComponent"
                  [inputs]="{counter}">
    <ng-container isLoading>Loading</ng-container>
  </async-component-loader>
  `,
})
class MyComponent {
  counter = 0;
  counterComponent = new LazyComponentCreator<CounterComponent>({
      component: async () => (await import('./components/counter/counter.component')).CounterComponent,
      outputs: {
        increment: (newCount = 0) => this.counter = newCount
      }
    }
  )
}

That's it 🥳

Package Sidebar

Install

npm i @gernsdorfer/async-component-loader

Weekly Downloads

18

Version

1.0.0

License

MIT

Unpacked Size

46.9 kB

Total Files

13

Last publish

Collaborators

  • gernsdorferl