createComponent
function
Creates a ComponentRef
instance based on provided component type and a set of options.
API
Usage Notes
function createComponent<C>( component: Type<C>, options: { environmentInjector: EnvironmentInjector; hostElement?: Element | undefined; elementInjector?: Injector | undefined; projectableNodes?: Node[][] | undefined; }): ComponentRef<C>;
createComponent
ComponentRef<C>
Creates a ComponentRef
instance based on provided component type and a set of options.
@paramoptions
{ environmentInjector: EnvironmentInjector; hostElement?: Element | undefined; elementInjector?: Injector | undefined; projectableNodes?: Node[][] | undefined; }
Set of options to use:
environmentInjector
: AnEnvironmentInjector
instance to be used for the component.hostElement
(optional): A DOM node that should act as a host node for the component. If not provided, Angular creates one based on the tag name used in the component selector (and falls back to usingdiv
if selector doesn't have tag name info).elementInjector
(optional): AnElementInjector
instance, see additional info about it here.projectableNodes
(optional): A list of DOM nodes that should be projected through<ng-content>
of the new component instance, e.g.,[[element1, element2]]
: projectselement1
andelement2
into the same<ng-content>
.[[element1, element2], [element3]]
: projectselement1
andelement2
into one<ng-content>
, andelement3
into a separate<ng-content>
.
@returns
ComponentRef<C>
Jump to details