1.0.0 • Published 1 year ago

@gernsdorfer/async-component-loader v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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 🥳