ViewContainerRef
Represents a container where one or more views can be attached to a component.
abstract class ViewContainerRef {
abstract element: ElementRef
abstract injector: Injector
abstract parentInjector: Injector
abstract length: number
abstract clear(): void
abstract get(index: number): ViewRef | null
abstract createEmbeddedView<C>(templateRef: TemplateRef<C>, context?: C, index?: number): EmbeddedViewRef<C>
abstract createComponent<C>(componentFactory: ComponentFactory<C>, index?: number, injector?: Injector, projectableNodes?: any[][], ngModule?: NgModuleRef<any>): ComponentRef<C>
abstract insert(viewRef: ViewRef, index?: number): ViewRef
abstract move(viewRef: ViewRef, currentIndex: number): ViewRef
abstract indexOf(viewRef: ViewRef): number
abstract remove(index?: number): void
abstract detach(index?: number): ViewRef | null
}
See also
Description
Can contain host views (created by instantiating a
component with the createComponent()
method), and embedded views
(created by instantiating a TemplateRef
with the createEmbeddedView()
method).
A view container instance can contain other view containers, creating a view hierarchy.
Properties
Property | Description |
---|---|
abstract element: ElementRef
|
Read-only.
Anchor element that specifies the location of this container in the containing view. Each view container can have only one anchor element, and each anchor element can have only a single view container. Root elements of views attached to this container become siblings of the anchor element in the rendered view. Access the |
abstract injector: Injector
|
Read-only.
The dependency injector for this view container. |
abstract parentInjector: Injector
|
Read-only. |
abstract length: number
|
Read-only.
Reports how many views are currently attached to this container. |
Methods
Destroys all views in this container. |
ParametersThere are no parameters. Returns
|
Retrieves a view from this container. |
||
Parameters
Returns
|
Instantiates an embedded view and inserts it into this container. |
ParametersReturns
|
Instantiates a single component and inserts its host view into this container. |
||||||||||
Parameters
Returns
|
Moves a view to a new location in this container. |
||||
Parameters
Returns |
Returns the index of a view within the current container. |
||
Parameters
Returns
|
Destroys a view attached to this container |
||
Parameters
Returns
|
Detaches a view from this container without destroying it.
Use along with |
||
Parameters
Returns
|