1.1.2 • Published 4 years ago

@wishtack/reactive-component-loader v1.1.2

Weekly downloads
217
License
MIT
Repository
github
Last release
4 years ago

Build Status Greenkeeper badge

What is Reactive Component Loader?

@wishtack/reactive-component-loader is an Angular module that allows:

  • declarative dynamic component insertion,
  • component lazy loading and not only with the router (even with AOT enabled),
  • passing @Inputs and @Outputs easily to the dynamically inserted component (using ng-dynamic-component).

Getting Started

1. Install

yarn add @wishtack/reactive-component-loader

or npm install --save @wishtack/reactive-component-loader

2. Setup

Add ReactiveComponentLoaderModule.forRoot() to the root module.

import { ReactiveComponentLoaderModule } from '@wishtack/reactive-component-loader';

@NgModule({
    ...
    imports: [
        ReactiveComponentLoaderModule.forRoot()
    ]
    ...
})
export class AppModule {
}

3. Declare lazy loaded modules

@NgModule({
    ...
    imports: [
        ReactiveComponentLoaderModule.withModule({
            moduleId: 'todo-form-v1',
            loadChildren: './todo-form-v1/todo-form-v1.module#TodoFormV1Module'
        }),
        ReactiveComponentLoaderModule.withModule({
            moduleId: 'todo-form-v2',
            loadChildren: './todo-form-v2/todo-form-v2.module#TodoFormV2Module'
        }),
    ]
    ...
})
export class TodoListModule {
}

4. Lazy load components

Using <wt-lazy>...

@Component({
    template: `
    <wt-lazy
        [location]="todoFormComponentLocation"
        [inputs]="{keywords: keywords}"
        [outputs]="{keywordsChange: onKeywordsChange}">
    `
})
export class SomeFeatureComponent {
    
    todoFormComponentLocation = {
        moduleId: 'todo-form-v1',
        selector: 'wt-todo-form-v1'
    };
    
    onKeywordsChange = (keywords: string) => {
        ...
    }
    
}

... or ngComponentOutlet

@Component({
    template: `
    <ng-container *ngIf="todoFormComponentRecipe$ | async as recipe">
        <ng-container *ngComponentOutlet="recipe.componentType; ngModuleFactory: recipe.ngModuleFactory"
    </ng-container>
    `
})
export class SomeFeatureComponent {
    
    todoFormComponentRecipe$ = this._reactiveComponentLoader.getComponentRecipe({
        moduleId: 'todo-form-v1',
        selector: 'wt-todo-form-v1'
    });
    
    constructor(private _reactiveComponentLoader: ReactiveComponentLoader) {
    }
    
}
1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.2.7

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

6 years ago

0.1.0

6 years ago