ViewContainerRef class abstract

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 ComponentFactory via createComponent, and embedded views, created by instantiating an TemplateRef 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 obtain it via a @ViewChild query.

Implemented types

Constructors

ViewContainerRef()

Properties

element ElementRef
Anchor element (the location of this container in the containing view).
no setter
hashCode int
The hash code for this object.
no setterinherited
injector Injector
Injector context for the view container within the larger app.
no setter
length int
Returns the number of views currently attached to this container.
no setter
parentInjector Injector
The parent injector context.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() → void
Destroys all views in this container.
createComponent<T extends Object>(ComponentFactory<T> componentFactory, [int index = -1, Injector? injector, List<List<Object>>? projectableNodes]) ComponentRef<T>
Instantiates a single component and inserts its host view into this container at the specified index.
createEmbeddedView(TemplateRef templateRef) EmbeddedViewRef
Instantiates 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) ViewRef
Returns the view located in this container at the specified index.
indexOf(ViewRef viewRef) int
Returns the index of the attached viewRef.
insert(ViewRef viewRef, [int index = -1]) ViewRef
Inserts a View identified by a ViewRef into the container.
insertEmbeddedView(TemplateRef templateRef, [int index = -1]) EmbeddedViewRef
Instantiates templateRef and inserts it into this container at index.
loadDetached<T extends Object>(ComponentFactory<T> component, {Injector? injector}) ComponentRef<T>
Creates and loads a new instance of the component defined by component.
inherited
loadNextTo<T extends Object>(ComponentFactory<T> component, {Injector? injector}) ComponentRef<T>
Creates and loads a new instance of the component defined by component.
inherited
loadNextToLocation<T extends Object>(ComponentFactory<T> component, ViewContainerRef location, {Injector? injector}) ComponentRef<T>
Creates and loads a new instance of the component defined by component.
inherited
move(ViewRef viewRef, [int index = -1]) → void
Moves the provided viewRef into the specified index.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove([int index = -1]) → void
Removes the view attached to this container at the specified index.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited