Project

General

Profile

1
/**
2
 * @license
3
 * Copyright Google Inc. All Rights Reserved.
4
 *
5
 * Use of this source code is governed by an MIT-style license that can be
6
 * found in the LICENSE file at https://angular.io/license
7
 */
8
import { Injector } from '../di/injector';
9
import { ComponentFactory, ComponentRef } from './component_factory';
10
import { ElementRef } from './element_ref';
11
import { NgModuleRef } from './ng_module_factory';
12
import { TemplateRef } from './template_ref';
13
import { EmbeddedViewRef, ViewRef } from './view_ref';
14
/**
15
 * Represents a container where one or more Views can be attached.
16
 *
17
 * The container can contain two kinds of Views. Host Views, created by instantiating a
18
 * {@link Component} via {@link #createComponent}, and Embedded Views, created by instantiating an
19
 * {@link TemplateRef Embedded Template} via {@link #createEmbeddedView}.
20
 *
21
 * The location of the View Container within the containing View is specified by the Anchor
22
 * `element`. Each View Container can have only one Anchor Element and each Anchor Element can only
23
 * have a single View Container.
24
 *
25
 * Root elements of Views attached to this container become siblings of the Anchor Element in
26
 * the Rendered View.
27
 *
28
 * To access a `ViewContainerRef` of an Element, you can either place a {@link Directive} injected
29
 * with `ViewContainerRef` on the Element, or you obtain it via a {@link ViewChild} query.
30
 * @stable
31
 */
32
export declare abstract class ViewContainerRef {
33
    /**
34
     * Anchor element that specifies the location of this container in the containing View.
35
     * <!-- TODO: rename to anchorElement -->
36
     */
37
    readonly abstract element: ElementRef;
38
    readonly abstract injector: Injector;
39
    readonly abstract parentInjector: Injector;
40
    /**
41
     * Destroys all Views in this container.
42
     */
43
    abstract clear(): void;
44
    /**
45
     * Returns the {@link ViewRef} for the View located in this container at the specified index.
46
     */
47
    abstract get(index: number): ViewRef | null;
48
    /**
49
     * Returns the number of Views currently attached to this container.
50
     */
51
    readonly abstract length: number;
52
    /**
53
     * Instantiates an Embedded View based on the {@link TemplateRef `templateRef`} and inserts it
54
     * into this container at the specified `index`.
55
     *
56
     * If `index` is not specified, the new View will be inserted as the last View in the container.
57
     *
58
     * Returns the {@link ViewRef} for the newly created View.
59
     */
60
    abstract createEmbeddedView<C>(templateRef: TemplateRef<C>, context?: C, index?: number): EmbeddedViewRef<C>;
61
    /**
62
     * Instantiates a single {@link Component} and inserts its Host View into this container at the
63
     * specified `index`.
64
     *
65
     * The component is instantiated using its {@link ComponentFactory} which can be
66
     * obtained via {@link ComponentFactoryResolver#resolveComponentFactory}.
67
     *
68
     * If `index` is not specified, the new View will be inserted as the last View in the container.
69
     *
70
     * You can optionally specify the {@link Injector} that will be used as parent for the Component.
71
     *
72
     * Returns the {@link ComponentRef} of the Host View created for the newly instantiated Component.
73
     */
74
    abstract createComponent<C>(componentFactory: ComponentFactory<C>, index?: number, injector?: Injector, projectableNodes?: any[][], ngModule?: NgModuleRef<any>): ComponentRef<C>;
75
    /**
76
     * Inserts a View identified by a {@link ViewRef} into the container at the specified `index`.
77
     *
78
     * If `index` is not specified, the new View will be inserted as the last View in the container.
79
     *
80
     * Returns the inserted {@link ViewRef}.
81
     */
82
    abstract insert(viewRef: ViewRef, index?: number): ViewRef;
83
    /**
84
     * Moves a View identified by a {@link ViewRef} into the container at the specified `index`.
85
     *
86
     * Returns the inserted {@link ViewRef}.
87
     */
88
    abstract move(viewRef: ViewRef, currentIndex: number): ViewRef;
89
    /**
90
     * Returns the index of the View, specified via {@link ViewRef}, within the current container or
91
     * `-1` if this container doesn't contain the View.
92
     */
93
    abstract indexOf(viewRef: ViewRef): number;
94
    /**
95
     * Destroys a View attached to this container at the specified `index`.
96
     *
97
     * If `index` is not specified, the last View in the container will be removed.
98
     */
99
    abstract remove(index?: number): void;
100
    /**
101
     * Use along with {@link #insert} to move a View within the current container.
102
     *
103
     * If the `index` param is omitted, the last {@link ViewRef} is detached.
104
     */
105
    abstract detach(index?: number): ViewRef | null;
106
}
(10-10/11)