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
is a class that extends ProjectionStrategy
. It lets you project a component into a container.
constructor(
component: T,
private containerStrategy: ContainerStrategy,
private contextStrategy?: ContextStrategy,
)
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(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
is a class that extends ProjectionStrategy
. It lets you project a component into the document, such as appending it to <body>
.
constructor(
component: T,
private contextStrategy?: ContextStrategy,
private domStrategy?: DomStrategy,
)
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(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
is a class that extends ProjectionStrategy
. It lets you project a template into a container.
constructor(
template: T,
private containerStrategy: ContainerStrategy,
private contextStrategy?: ContextStrategy,
)
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(): 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 are accessible via PROJECTION_STRATEGY
constant.
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.
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.
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.
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.
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.
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.
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.