@@ -10,25 +10,52 @@ import {TemplateRef} from './template_ref';
1010import { ViewRef , HostViewRef , ProtoViewRef , internalView } from './view_ref' ;
1111
1212/**
13- * A location where { @link ViewRef}s can be attached.
13+ * Represents a container where one or more Views can be attached.
1414 *
15- * A `ViewContainerRef` represents a location in a {@link ViewRef} where other child
16- * {@link ViewRef}s can be inserted. Adding and removing views is the only way of structurally
17- * changing the rendered DOM of the application.
15+ * The container can contain two kinds of Views. Host Views, created by instantiating a
16+ * {@link Component} via {@link #createHostView}s, and Embedded Views, created by instantiating an
17+ * {@link TemplateRef Embedded Template} via {@link #createEmbeddedView}).
18+ *
19+ * The location of the View Container within the containing View is specified by the Anchor
20+ * `element`. Each View Container can have only one Anchor Element and each Anchor Element can only
21+ * have a single View Container.
22+ *
23+ * Root elements of Views attached to this container become siblings of the Anchor Element in
24+ * the Rendered View.
25+ *
26+ * To access a ViewContainerRef of an Element, you can either place a {@link Directive} injected
27+ * with `ViewContainerRef` on the Element, or you obtain it via
28+ * {@link ViewManager#getViewContainer}.
29+ *
30+ * <!-- TODO: Is ViewContainerRef#element a public api? Should it be renamed? to anchor or anchorElementRef? -->
31+ * <!-- TODO: rename all atIndex params to just index or get(index) to get(atIndex) -->
1832 */
1933export class ViewContainerRef {
34+
2035 /**
2136 * @private
2237 */
23- constructor ( public viewManager : avmModule . AppViewManager , public element : ElementRef ) { }
38+ constructor (
39+ /**
40+ * @private
41+ */
42+ public viewManager : avmModule . AppViewManager ,
43+
44+ /**
45+ * Anchor element that specifies the location of this container in the containing View.
46+ */
47+ public element : ElementRef
48+ ) {
49+
50+ }
2451
2552 private _getViews ( ) : Array < viewModule . AppView > {
2653 var vc = internalView ( this . element . parentView ) . viewContainers [ this . element . boundElementIndex ] ;
2754 return isPresent ( vc ) ? vc . views : [ ] ;
2855 }
2956
3057 /**
31- * Remove all { @link ViewRef}s at current location .
58+ * Destroys all Views in the container .
3259 */
3360 clear ( ) : void {
3461 for ( var i = this . length - 1 ; i >= 0 ; i -- ) {
@@ -37,28 +64,22 @@ export class ViewContainerRef {
3764 }
3865
3966 /**
40- * Return a {@link ViewRef} at specific index.
67+ * Returns the {@link ViewRef} for the View located in this container at the specified index.
4168 */
4269 get ( index : number ) : ViewRef { return this . _getViews ( ) [ index ] . ref ; }
4370
4471 /**
45- * Returns number of { @link ViewRef}s currently attached at this location .
72+ * Returns the number of Views currently attached to this container .
4673 */
4774 get length ( ) : number { return this . _getViews ( ) . length ; }
4875
4976 /**
50- * Create and insert a {@link ViewRef} into the view-container.
77+ * Instantiates an Embedded View based on the {@link TemplateRef `templateRef`} and inserts it
78+ * into this container at index specified via `atIndex`.
5179 *
52- * - `protoViewRef` (optional) {@link ProtoViewRef} - The `ProtoView` to use for creating
53- * `View` to be inserted at this location. If `ViewContainer` is created at a location
54- * of inline template, then `protoViewRef` is the `ProtoView` of the template.
55- * - `atIndex` (optional) `number` - location of insertion point. (Or at the end if unspecified.)
56- * - `context` (optional) {@link ElementRef} - Context (for expression evaluation) from the
57- * {@link ElementRef} location. (Or current context if unspecified.)
58- * - `bindings` (optional) Array of {@link ResolvedBinding} - Used for configuring
59- * `ElementInjector`.
80+ * If `atIndex` is not specified, the new View will be inserted as the last View in the container.
6081 *
61- * Returns newly created {@link ViewRef}.
82+ * Returns the {@link ViewRef} for the newly created View .
6283 */
6384 // TODO(rado): profile and decide whether bounds checks should be added
6485 // to the methods below.
@@ -67,6 +88,20 @@ export class ViewContainerRef {
6788 return this . viewManager . createEmbeddedViewInContainer ( this . element , atIndex , templateRef ) ;
6889 }
6990
91+ /**
92+ * Instantiates a single {@link Component} and inserts it into this container at index specified
93+ * via `atIndex`.
94+ *
95+ * The component is instantiated using its {@link ProtoViewRef `protoViewRef`} which can be
96+ * obtained via {@link Compiler#compileInHost}.
97+ *
98+ * If `atIndex` is not specified, the new View will be inserted as the last View in the container.
99+ *
100+ * You can optionally specify `dynamicallyCreatedBindings`, which configure the {@link Injector}
101+ * that will be created for the new Host View. <!-- TODO: what is host view? it's never defined!!! -->
102+ *
103+ * Returns the {@link ViewRef} for the newly created View.
104+ */
70105 createHostView ( protoViewRef : ProtoViewRef = null , atIndex : number = - 1 ,
71106 dynamicallyCreatedBindings : ResolvedBinding [ ] = null ) : HostViewRef {
72107 if ( atIndex == - 1 ) atIndex = this . length ;
@@ -75,29 +110,32 @@ export class ViewContainerRef {
75110 }
76111
77112 /**
78- * Insert a {@link ViewRef} at specefic index.
113+ * <!-- TODO: refactor into move and remove -->
114+ * Inserts a View identified by a {@link ViewRef} into the container at index specified via
115+ * `atIndex`.
79116 *
80- * The index is location at which the {@link ViewRef} should be attached. If omitted it is
81- * inserted at the end.
117+ * If `atIndex` is not specified, the new View will be inserted as the last View in the container.
82118 *
83119 * Returns the inserted {@link ViewRef}.
120+ * <!-- TODO: why does it return ViewRef? looks useless -->
84121 */
85122 insert ( viewRef : ViewRef , atIndex : number = - 1 ) : ViewRef {
86123 if ( atIndex == - 1 ) atIndex = this . length ;
87124 return this . viewManager . attachViewInContainer ( this . element , atIndex , viewRef ) ;
88125 }
89126
90127 /**
91- * Return the index of already inserted {@link ViewRef}.
128+ * Returns the index of the View, specified via {@link ViewRef}, within the current container .
92129 */
93130 indexOf ( viewRef : ViewRef ) : number {
94131 return ListWrapper . indexOf ( this . _getViews ( ) , internalView ( viewRef ) ) ;
95132 }
96133
97134 /**
98- * Remove a {@link ViewRef} at specific index.
135+ * <!-- TODO: rename to destroy -->
136+ * Destroys a View attached to this container at index specified via `atIndex`.
99137 *
100- * If the index is omitted last { @link ViewRef} is removed.
138+ * If `atIndex` is not specified, the last View in the container will be removed.
101139 */
102140 remove ( atIndex : number = - 1 ) : void {
103141 if ( atIndex == - 1 ) atIndex = this . length - 1 ;
@@ -106,8 +144,11 @@ export class ViewContainerRef {
106144 }
107145
108146 /**
109- * The method can be used together with insert to implement a view move, i.e.
110- * moving the DOM nodes while the directives in the view stay intact.
147+ * <!-- TODO: refactor into move and remove -->
148+ * Use along with {@link #insert} to move a View within the current container.
149+ *
150+ * If the `atIndex` param is omitted, the last {@link ViewRef} is detached.
151+ * <!-- TODO: why does it return ViewRef? looks useless -->
111152 */
112153 detach ( atIndex : number = - 1 ) : ViewRef {
113154 if ( atIndex == - 1 ) atIndex = this . length - 1 ;
0 commit comments