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
component
is class of the component you would like to project.containerStrategy
is theContainerStrategy
that will be used when projecting the component.contextStrategy
is theContextStrategy
that will be used on the projected component. (default: None)
Please refer to ContainerStrategy and ContextStrategy documentation for their usage.
injectContent
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
component
is class of the component you would like to project.contextStrategy
is theContextStrategy
that will be used on the projected component. (default: None)domStrategy
is theDomStrategy
that will be used when inserting component. (default: AppendToBody)
Please refer to ContextStrategy and DomStrategy documentation for their usage.
injectContent
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
template
isTemplateRef
you would like to project.containerStrategy
is theContainerStrategy
that will be used when projecting the component.contextStrategy
is theContextStrategy
that will be used on the projected component. (default: None)
Please refer to ContainerStrategy and ContextStrategy documentation for their usage.
injectContent
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
Sets given context to the component and places it at the end of <body>
tag in the document.
AppendComponentToContainer
Sets given context to the component and places it at the end of the container.
AppendTemplateToContainer
Sets given context to the template and places it at the end of the container.
PrependComponentToContainer
Sets given context to the component and places it at the beginning of the container.
PrependTemplateToContainer
Sets given context to the template and places it at the beginning of the container.
ProjectComponentToContainer
Clears the container, sets given context to the component, and places it in the cleared the container.
ProjectTemplateToContainer
Clears the container, sets given context to the template, and places it in the cleared the container.