1.0.0 • Published 2 years ago
@rakutentech/angular-dynamic-component-loader v1.0.0
Angular Dynamic Component Loader
This library exposes a dynamic loader for angular components.
Table of contents
Prerequisites
- Angular (> 9.0.0)
Installation
- Install Angular Dynamic Component Loader:
npm install @rakutentech/angular-dynamic-component-loader
Usage
To use Angular Dynamic Component Loader, you will need to import the DynamicComponentLoaderService
:
import { DynamicComponentLoaderService } from '@rakutentech/angular-dynamic-component-loader';
You can now create a dynamic component. This is done by calling the loadComponent()
method of the service, which first needs to be injected:
// ...
constructor(
private readonly dynamicComponentLoaderService: DynamicComponentLoaderService,
// ...
) {}
// ...
const component = this.dynamicComponentLoaderService.loadComponent(componentType, {}, true, instanceInjector);
It takes four arguments:
- The class name of the dynamically loaded component.
- The data of the component instance.
- Should be set to
true
if the view should be assigned to a viewContainer - The providers injector of the component instance.
License
MIT