ViewContainerRef class

Represents a container where one or more Views can be attached.

The container can contain two kinds of Views. Host Views, created by instantiating a Component via #createComponent, and Embedded Views, created by instantiating an TemplateRef Embedded Template via #createEmbeddedView.

The location of the View Container within the containing View is specified by the Anchor element. Each View Container can have only one Anchor Element and each Anchor Element can only have a single View Container.

Root elements of Views attached to this container become siblings of the Anchor Element in the Rendered View.

To access a ViewContainerRef of an Element, you can either place a Directive injected with ViewContainerRef on the Element, or you obtain it via a ViewChild query.

Implemented types

Constructors

ViewContainerRef()

Properties

element ElementRef
Anchor element that specifies the location of this container in the containing View.
read-only
injector Injector
read-only
length → int
Returns the number of Views currently attached to this container.
read-only
parentInjector Injector
read-only
hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

clear() → void
Destroys all Views in this container.
createComponent<T>(ComponentFactory<T> componentFactory, [ int index = -1, Injector injector, List<List> projectableNodes ]) ComponentRef<T>
Instantiates a single Component and inserts its Host View into this container at the specified index. [...]
createEmbeddedView(TemplateRef templateRef) EmbeddedViewRef
Instantiates an Embedded View based on the TemplateRef `templateRef` and appends it into this container.
detach([int index = -1 ]) ViewRef
Use along with #insert to move a View within the current container. [...]
get(int index) EmbeddedViewRef
Returns the ViewRef for the View located in this container at the specified index.
indexOf(ViewRef viewRef) → int
Returns the index of the View, specified via ViewRef, within the current container or -1 if this container doesn't contain the View.
insert(ViewRef viewRef, [ int index = -1 ]) ViewRef
Inserts a View identified by a ViewRef into the container. [...]
insertEmbeddedView(TemplateRef templateRef, int index) EmbeddedViewRef
Instantiates an Embedded View based on the TemplateRef `templateRef` and inserts it into this container at the specified index. [...]
move(ViewRef viewRef, int currentIndex) ViewRef
remove([int index = -1 ]) → void
Destroys a View attached to this container at the specified index. [...]
loadDetached<T>(ComponentFactory<T> component, { Injector injector }) ComponentRef<T>
Creates and loads a new instance of the component defined by component. [...]
@mustCallSuper, inherited
loadNextTo<T>(ComponentFactory<T> component, { Injector injector }) ComponentRef<T>
Creates and loads a new instance of the component defined by component. [...]
inherited
loadNextToLocation<T>(ComponentFactory<T> component, ViewContainerRef location, { Injector injector }) ComponentRef<T>
Creates and loads a new instance of the component defined by component. [...]
@mustCallSuper, inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) → bool
The equality operator. [...]
inherited