Class

ComponentRendererComponent

ComponentRendererComponent()

Constructor

# new ComponentRendererComponent()

This component provides a flexible way to dynamically render Angular components at runtime based on a tag name. It handles the creation, property binding, and event subscription for dynamically loaded components. This is particularly useful for building configurable UIs where components need to be determined at runtime.

Dynamic component renderer for Decaf Angular applications.

classDiagram class ComponentRendererComponent { +ViewContainerRef vcr +string tag +Record~string, unknown~ globals +EnvironmentInjector injector +ComponentRef~unknown~ component +EventEmitter~RendererCustomEvent~ listenEvent +ngOnInit() +ngOnDestroy() +ngOnChanges(changes) -createComponent(tag, globals) -subscribeEvents() -unsubscribeEvents() } ComponentRendererComponent --|> OnInit ComponentRendererComponent --|> OnChanges ComponentRendererComponent --|> OnDestroy
Implements:
  • OnInit
  • OnChanges
  • OnDestroy

View Source lib/components/component-renderer/component-renderer.component.ts, line 51

Example
<ngx-decaf-component-renderer
  [tag]="tag"
  [globals]="globals"
  (listenEvent)="listenEvent($event)">
</ngx-decaf-component-renderer>

Classes

ComponentRendererComponent

This component provides a flexible way to dynamically render Angular components at runtime based on a tag name. It handles the creation, property binding, and event subscription for dynamically loaded components. This is particularly useful for building configurable UIs where components need to be determined at runtime.

ComponentRendererComponent

Initializes a new ComponentRendererComponent. This component doesn't require any dependencies to be injected in its constructor as it uses the inject function to obtain the EnvironmentInjector.

Members

ComponentRef.<unknown>

# component

This property holds a reference to the ComponentRef of the dynamically created component. It's used to interact with the component instance, subscribe to its events, and properly destroy it when the renderer is destroyed.

Reference to the dynamically created component.

View Source lib/components/component-renderer/component-renderer.component.ts, line 449

Record.<string, unknown>

# globals

This input property allows passing a set of properties to the dynamically rendered component. These properties will be mapped to the component's inputs if they match. Properties that don't match any input on the target component will be filtered out with a warning.

Global properties to pass to the rendered component.

Default Value:
  • {}

View Source lib/components/component-renderer/component-renderer.component.ts, line 426

EnvironmentInjector

# injector

This injector is used when creating the dynamic component to provide it with access to the application's dependency injection system. It ensures that the dynamically created component can access the same services and dependencies as statically created components.

Injector used for dependency injection in the dynamic component.

View Source lib/components/component-renderer/component-renderer.component.ts, line 438

EventEmitter.<RendererCustomEvent>

# listenEvent

This output property emits events that originate from the dynamically rendered component. It allows the parent component to listen for and respond to events from the dynamic component, creating a communication channel between the parent and the dynamically rendered child.

Event emitter for events from the rendered component.

View Source lib/components/component-renderer/component-renderer.component.ts, line 461

Logger

# logger

This property holds a Logger instance specific to this component. It's used to log information, warnings, and errors related to the component's operations, particularly useful for debugging and monitoring the dynamic component rendering process.

Logger instance for the component.

View Source lib/components/component-renderer/component-renderer.component.ts, line 473

Model | undefined

# model

The data model repository that this component will use for CRUD operations. This provides a connection to the data layer for retrieving and manipulating data.

Repository model for data operations.

View Source lib/components/component-renderer/component-renderer.component.ts, line 136

Model | undefined

# model

The data model repository that this component will use for CRUD operations. This provides a connection to the data layer for retrieving and manipulating data.

Repository model for data operations.

View Source lib/components/component-renderer/component-renderer.component.ts, line 482

string

# tag

This input property specifies which component should be rendered by providing its registered tag name. The tag must correspond to a component that has been registered with the NgxRenderingEngine. This is a required input as it determines which component to create.

The tag name of the component to be dynamically rendered.

View Source lib/components/component-renderer/component-renderer.component.ts, line 413

ViewContainerRef

# vcr

This ViewContainerRef provides the container where the dynamically created component will be inserted into the DOM. It's marked as static to ensure it's available during the ngOnInit lifecycle hook when the component is created.

Reference to the container where the dynamic component will be rendered.

View Source lib/components/component-renderer/component-renderer.component.ts, line 400

ComponentRef.<unknown>

# static component

This property holds a reference to the ComponentRef of the dynamically created component. It's used to interact with the component instance, subscribe to its events, and properly destroy it when the renderer is destroyed.

Reference to the dynamically created component.

View Source lib/components/component-renderer/component-renderer.component.ts, line 106

Record.<string, unknown>

# static globals

This input property allows passing a set of properties to the dynamically rendered component. These properties will be mapped to the component's inputs if they match. Properties that don't match any input on the target component will be filtered out with a warning.

Global properties to pass to the rendered component.

Default Value:
  • {}

View Source lib/components/component-renderer/component-renderer.component.ts, line 85

EnvironmentInjector

# static injector

This injector is used when creating the dynamic component to provide it with access to the application's dependency injection system. It ensures that the dynamically created component can access the same services and dependencies as statically created components.

Injector used for dependency injection in the dynamic component.

View Source lib/components/component-renderer/component-renderer.component.ts, line 96

EventEmitter.<RendererCustomEvent>

# static listenEvent

This output property emits events that originate from the dynamically rendered component. It allows the parent component to listen for and respond to events from the dynamic component, creating a communication channel between the parent and the dynamically rendered child.

Event emitter for events from the rendered component.

View Source lib/components/component-renderer/component-renderer.component.ts, line 117

Logger

# static logger

This property holds a Logger instance specific to this component. It's used to log information, warnings, and errors related to the component's operations, particularly useful for debugging and monitoring the dynamic component rendering process.

Logger instance for the component.

View Source lib/components/component-renderer/component-renderer.component.ts, line 128

string

# static tag

This input property specifies which component should be rendered by providing its registered tag name. The tag must correspond to a component that has been registered with the NgxRenderingEngine. This is a required input as it determines which component to create.

The tag name of the component to be dynamically rendered.

View Source lib/components/component-renderer/component-renderer.component.ts, line 73

ViewContainerRef

# static vcr

This ViewContainerRef provides the container where the dynamically created component will be inserted into the DOM. It's marked as static to ensure it's available during the ngOnInit lifecycle hook when the component is created.

Reference to the container where the dynamic component will be rendered.

View Source lib/components/component-renderer/component-renderer.component.ts, line 61

Methods

# async ngOnDestroy() → {Promise.<void>}

Performs cleanup operations when the component is being destroyed by Angular. This includes unsubscribing from all event emitters of the dynamic component and destroying the rendering engine instance to prevent memory leaks.

Cleans up resources when the component is destroyed.

sequenceDiagram participant A as Angular Lifecycle participant C as ComponentRendererComponent participant R as NgxRenderingEngine A->>C: ngOnDestroy() alt component exists C->>C: unsubscribeEvents() C->>R: destroy() end

View Source lib/components/component-renderer/component-renderer.component.ts, line 542

A promise that resolves when cleanup is complete

Promise.<void>

# ngOnInit() → {void}

Sets up the component by creating the dynamic component specified by the tag input. This method is called once when the component is initialized and triggers the dynamic component creation process with the provided tag name and global properties.

Initializes the component after Angular first displays the data-bound properties.

sequenceDiagram participant A as Angular Lifecycle participant C as ComponentRendererComponent participant R as NgxRenderingEngine A->>C: ngOnInit() C->>C: createComponent(tag, globals) C->>R: components(tag) R-->>C: Return component constructor C->>C: Process component inputs C->>C: Create component instance C->>C: subscribeEvents()

View Source lib/components/component-renderer/component-renderer.component.ts, line 518

void