ProjectionStrategy

ProjectionStrategy is an abstract class exposed by @abp/ng.core package. There are three projection strategies extending it: ComponentProjectionStrategy, RootComponentProjectionStrategy, and TemplateProjectionStrategy. Implementing the same methods and properties, all of these strategies help you define how your content projection will work.

ComponentProjectionStrategy

ComponentProjectionStrategy is a class that extends ProjectionStrategy. It lets you project a component into a container.

constructor

constructor(
  component: T,
  private containerStrategy: ContainerStrategy,
  private contextStrategy?: ContextStrategy,
)
  • component is class of the component you would like to project.
  • containerStrategy is the ContainerStrategy that will be used when projecting the component.
  • contextStrategy is the ContextStrategy that will be used on the projected component. (default: None)

Please refer to ContainerStrategy and ContextStrategy documentation for their usage.

injectContent

injectContent(injector: Injector): ComponentRef<T>

This method prepares the container, resolves the component, sets its context, and projects it to the container. It returns a ComponentRef instance, which you should keep in order to clear projected components later on.

RootComponentProjectionStrategy

RootComponentProjectionStrategy is a class that extends ProjectionStrategy. It lets you project a component into the document, such as appending it to <body>.

constructor

constructor(
  component: T,
  private contextStrategy?: ContextStrategy,
  private domStrategy?: DomStrategy,
)
  • component is class of the component you would like to project.
  • contextStrategy is the ContextStrategy that will be used on the projected component. (default: None)
  • domStrategy is the DomStrategy that will be used when inserting component. (default: AppendToBody)

Please refer to ContextStrategy and DomStrategy documentation for their usage.

injectContent

injectContent(injector: Injector): ComponentRef<T>

This method resolves the component, sets its context, and projects it to the document. It returns a ComponentRef instance, which you should keep in order to clear projected components later on.

TemplateProjectionStrategy

TemplateProjectionStrategy is a class that extends ProjectionStrategy. It lets you project a template into a container.

constructor

constructor(
  template: T,
  private containerStrategy: ContainerStrategy,
  private contextStrategy?: ContextStrategy,
)
  • template is TemplateRef you would like to project.
  • containerStrategy is the ContainerStrategy that will be used when projecting the component.
  • contextStrategy is the ContextStrategy that will be used on the projected component. (default: None)

Please refer to ContainerStrategy and ContextStrategy documentation for their usage.

injectContent

injectContent(): EmbeddedViewRef<T>

This method prepares the container, and projects the template together with the defined context to it. It returns an EmbeddedViewRef, which you should keep in order to clear projected templates later on.

Predefined Projection Strategies

Predefined projection strategies are accessible via PROJECTION_STRATEGY constant.

AppendComponentToBody

PROJECTION_STRATEGY.AppendComponentToBody(
  component: T,
  contextStrategy?: ComponentContextStrategy<T>,
)

Sets given context to the component and places it at the end of <body> tag in the document.

AppendComponentToContainer

PROJECTION_STRATEGY.AppendComponentToContainer(
  component: T,
  containerRef: ViewContainerRef,
  contextStrategy?: ComponentContextStrategy<T>,
)

Sets given context to the component and places it at the end of the container.

AppendTemplateToContainer

PROJECTION_STRATEGY.AppendTemplateToContainer(
  templateRef: T,
  containerRef: ViewContainerRef,
  contextStrategy?: ComponentContextStrategy<T>,
)

Sets given context to the template and places it at the end of the container.

PrependComponentToContainer

PROJECTION_STRATEGY.PrependComponentToContainer(
  component: T,
  containerRef: ViewContainerRef,
  contextStrategy?: ComponentContextStrategy<T>,
)

Sets given context to the component and places it at the beginning of the container.

PrependTemplateToContainer

PROJECTION_STRATEGY.PrependTemplateToContainer(
  templateRef: T,
  containerRef: ViewContainerRef,
  contextStrategy?: ComponentContextStrategy<T>,
)

Sets given context to the template and places it at the beginning of the container.

ProjectComponentToContainer

PROJECTION_STRATEGY.ProjectComponentToContainer(
  component: T,
  containerRef: ViewContainerRef,
  contextStrategy?: ComponentContextStrategy<T>,
)

Clears the container, sets given context to the component, and places it in the cleared the container.

ProjectTemplateToContainer

PROJECTION_STRATEGY.ProjectTemplateToContainer(
  templateRef: T,
  containerRef: ViewContainerRef,
  contextStrategy?: ComponentContextStrategy<T>,
)

Clears the container, sets given context to the template, and places it in the cleared the container.

See Also

Contributors


Last updated: July 31, 2024 Edit this page on GitHub

Was this page helpful?

Please make a selection.

To help us improve, please share your reason for the negative feedback in the field below.

Please enter a note.

Thank you for your valuable feedback!

Please note that although we cannot respond to feedback, our team will use your comments to improve the experience.

In this document
Community Talks

What’s New with .NET 9 & ABP 9?

21 Nov, 17:00
Online
Watch the Event
Mastering ABP Framework Book
Mastering ABP Framework

This book will help you gain a complete understanding of the framework and modern web application development techniques.

Learn More