diff --git a/modules/angular2/src/core/compiler/view_container_ref.ts b/modules/angular2/src/core/compiler/view_container_ref.ts index 453d4efdd0..a769aef21d 100644 --- a/modules/angular2/src/core/compiler/view_container_ref.ts +++ b/modules/angular2/src/core/compiler/view_container_ref.ts @@ -28,7 +28,6 @@ import {ViewRef, HostViewRef, ProtoViewRef, internalView} from './view_ref'; * {@link ViewManager#getViewContainer}. * * - * */ export class ViewContainerRef { @@ -75,53 +74,52 @@ export class ViewContainerRef { /** * Instantiates an Embedded View based on the {@link TemplateRef `templateRef`} and inserts it - * into this container at index specified via `atIndex`. + * into this container at the specified `index`. * - * If `atIndex` is not specified, the new View will be inserted as the last View in the container. + * If `index` is not specified, the new View will be inserted as the last View in the container. * * Returns the {@link ViewRef} for the newly created View. */ // TODO(rado): profile and decide whether bounds checks should be added // to the methods below. - createEmbeddedView(templateRef: TemplateRef, atIndex: number = -1): ViewRef { - if (atIndex == -1) atIndex = this.length; - return this.viewManager.createEmbeddedViewInContainer(this.element, atIndex, templateRef); + createEmbeddedView(templateRef: TemplateRef, index: number = -1): ViewRef { + if (index == -1) index = this.length; + return this.viewManager.createEmbeddedViewInContainer(this.element, index, templateRef); } /** - * Instantiates a single {@link Component} and inserts it into this container at index specified - * via `atIndex`. + * Instantiates a single {@link Component} and inserts it into this container at the specified + * `index`. * * The component is instantiated using its {@link ProtoViewRef `protoViewRef`} which can be * obtained via {@link Compiler#compileInHost}. * - * If `atIndex` is not specified, the new View will be inserted as the last View in the container. + * If `index` is not specified, the new View will be inserted as the last View in the container. * * You can optionally specify `dynamicallyCreatedBindings`, which configure the {@link Injector} * that will be created for the new Host View. * * Returns the {@link ViewRef} for the newly created View. */ - createHostView(protoViewRef: ProtoViewRef = null, atIndex: number = -1, + createHostView(protoViewRef: ProtoViewRef = null, index: number = -1, dynamicallyCreatedBindings: ResolvedBinding[] = null): HostViewRef { - if (atIndex == -1) atIndex = this.length; - return this.viewManager.createHostViewInContainer(this.element, atIndex, protoViewRef, + if (index == -1) index = this.length; + return this.viewManager.createHostViewInContainer(this.element, index, protoViewRef, dynamicallyCreatedBindings); } /** * - * Inserts a View identified by a {@link ViewRef} into the container at index specified via - * `atIndex`. + * Inserts a View identified by a {@link ViewRef} into the container at the specified `index`. * - * If `atIndex` is not specified, the new View will be inserted as the last View in the container. + * If `index` is not specified, the new View will be inserted as the last View in the container. * * Returns the inserted {@link ViewRef}. * */ - insert(viewRef: ViewRef, atIndex: number = -1): ViewRef { - if (atIndex == -1) atIndex = this.length; - return this.viewManager.attachViewInContainer(this.element, atIndex, viewRef); + insert(viewRef: ViewRef, index: number = -1): ViewRef { + if (index == -1) index = this.length; + return this.viewManager.attachViewInContainer(this.element, index, viewRef); } /** @@ -133,13 +131,13 @@ export class ViewContainerRef { /** * - * Destroys a View attached to this container at index specified via `atIndex`. + * Destroys a View attached to this container at the specified `index`. * - * If `atIndex` is not specified, the last View in the container will be removed. + * If `index` is not specified, the last View in the container will be removed. */ - remove(atIndex: number = -1): void { - if (atIndex == -1) atIndex = this.length - 1; - this.viewManager.destroyViewInContainer(this.element, atIndex); + remove(index: number = -1): void { + if (index == -1) index = this.length - 1; + this.viewManager.destroyViewInContainer(this.element, index); // view is intentionally not returned to the client. } @@ -147,11 +145,11 @@ export class ViewContainerRef { * * Use along with {@link #insert} to move a View within the current container. * - * If the `atIndex` param is omitted, the last {@link ViewRef} is detached. + * If the `index` param is omitted, the last {@link ViewRef} is detached. * */ - detach(atIndex: number = -1): ViewRef { - if (atIndex == -1) atIndex = this.length - 1; - return this.viewManager.detachViewInContainer(this.element, atIndex); + detach(index: number = -1): ViewRef { + if (index == -1) index = this.length - 1; + return this.viewManager.detachViewInContainer(this.element, index); } } diff --git a/modules/angular2/src/core/compiler/view_manager.ts b/modules/angular2/src/core/compiler/view_manager.ts index 047260476a..fda1de951f 100644 --- a/modules/angular2/src/core/compiler/view_manager.ts +++ b/modules/angular2/src/core/compiler/view_manager.ts @@ -183,14 +183,14 @@ export class AppViewManager { * * See {@link AppViewManager#destroyViewInContainer}. */ - createEmbeddedViewInContainer(viewContainerLocation: ElementRef, atIndex: number, + createEmbeddedViewInContainer(viewContainerLocation: ElementRef, index: number, templateRef: TemplateRef): ViewRef { var s = this._createEmbeddedViewInContainerScope(); var protoView = internalProtoView(templateRef.protoViewRef); if (protoView.type !== ViewType.EMBEDDED) { throw new BaseException('This method can only be called with embedded ProtoViews!'); } - return wtfLeave(s, this._createViewInContainer(viewContainerLocation, atIndex, protoView, + return wtfLeave(s, this._createViewInContainer(viewContainerLocation, index, protoView, templateRef.elementRef, null)); } @@ -201,7 +201,7 @@ export class AppViewManager { * * See {@link AppViewManager#destroyViewInContainer}. */ - createHostViewInContainer(viewContainerLocation: ElementRef, atIndex: number, + createHostViewInContainer(viewContainerLocation: ElementRef, index: number, protoViewRef: ProtoViewRef, imperativelyCreatedInjector: ResolvedBinding[]): HostViewRef { var s = this._createHostViewInContainerScope(); @@ -210,7 +210,7 @@ export class AppViewManager { throw new BaseException('This method can only be called with host ProtoViews!'); } return wtfLeave( - s, this._createViewInContainer(viewContainerLocation, atIndex, protoView, + s, this._createViewInContainer(viewContainerLocation, index, protoView, viewContainerLocation, imperativelyCreatedInjector)); } @@ -218,7 +218,7 @@ export class AppViewManager { * * See {@link AppViewManager#destroyViewInContainer}. */ - _createViewInContainer(viewContainerLocation: ElementRef, atIndex: number, + _createViewInContainer(viewContainerLocation: ElementRef, index: number, protoView: viewModule.AppProtoView, context: ElementRef, imperativelyCreatedInjector: ResolvedBinding[]): ViewRef { var parentView = internalView(viewContainerLocation.parentView); @@ -231,30 +231,30 @@ export class AppViewManager { !embeddedFragmentView.hydrated()) { // Case 1: instantiate the first view of a template that has been merged into a parent view = embeddedFragmentView; - this._attachRenderView(parentView, boundElementIndex, atIndex, view); + this._attachRenderView(parentView, boundElementIndex, index, view); } else { // Case 2: instantiate another copy of the template or a host ProtoView. // This is a separate case // as we only inline one copy of the template into the parent view. view = this._createPooledView(protoView); - this._attachRenderView(parentView, boundElementIndex, atIndex, view); + this._attachRenderView(parentView, boundElementIndex, index, view); this._renderer.hydrateView(view.render); } this._utils.attachViewInContainer(parentView, boundElementIndex, contextView, - contextBoundElementIndex, atIndex, view); + contextBoundElementIndex, index, view); this._utils.hydrateViewInContainer(parentView, boundElementIndex, contextView, - contextBoundElementIndex, atIndex, + contextBoundElementIndex, index, imperativelyCreatedInjector); return view.ref; } - _attachRenderView(parentView: viewModule.AppView, boundElementIndex: number, atIndex: number, + _attachRenderView(parentView: viewModule.AppView, boundElementIndex: number, index: number, view: viewModule.AppView) { var elementRef = parentView.elementRefs[boundElementIndex]; - if (atIndex === 0) { + if (index === 0) { this._renderer.attachFragmentAfterElement(elementRef, view.renderFragment); } else { - var prevView = parentView.viewContainers[boundElementIndex].views[atIndex - 1]; + var prevView = parentView.viewContainers[boundElementIndex].views[index - 1]; this._renderer.attachFragmentAfterFragment(prevView.renderFragment, view.renderFragment); } } @@ -265,11 +265,11 @@ export class AppViewManager { * * See {@link AppViewManager#createViewInContainer}. */ - destroyViewInContainer(viewContainerLocation: ElementRef, atIndex: number) { + destroyViewInContainer(viewContainerLocation: ElementRef, index: number) { var s = this._destroyViewInContainerScope(); var parentView = internalView(viewContainerLocation.parentView); var boundElementIndex = viewContainerLocation.boundElementIndex; - this._destroyViewInContainer(parentView, boundElementIndex, atIndex); + this._destroyViewInContainer(parentView, boundElementIndex, index); wtfLeave(s); } @@ -279,7 +279,7 @@ export class AppViewManager { * * See {@link AppViewManager#detachViewInContainer}. */ - attachViewInContainer(viewContainerLocation: ElementRef, atIndex: number, + attachViewInContainer(viewContainerLocation: ElementRef, index: number, viewRef: ViewRef): ViewRef { var s = this._attachViewInContainerScope(); var view = internalView(viewRef); @@ -291,8 +291,8 @@ export class AppViewManager { // previous parent injector (see https://github.com/angular/angular/issues/1377). // Right now we are destroying any special // context view that might have been used. - this._utils.attachViewInContainer(parentView, boundElementIndex, null, null, atIndex, view); - this._attachRenderView(parentView, boundElementIndex, atIndex, view); + this._utils.attachViewInContainer(parentView, boundElementIndex, null, null, index, view); + this._attachRenderView(parentView, boundElementIndex, index, view); return wtfLeave(s, viewRef); } @@ -302,13 +302,13 @@ export class AppViewManager { * * See {@link AppViewManager#attachViewInContainer}. */ - detachViewInContainer(viewContainerLocation: ElementRef, atIndex: number): ViewRef { + detachViewInContainer(viewContainerLocation: ElementRef, index: number): ViewRef { var s = this._detachViewInContainerScope(); var parentView = internalView(viewContainerLocation.parentView); var boundElementIndex = viewContainerLocation.boundElementIndex; var viewContainer = parentView.viewContainers[boundElementIndex]; - var view = viewContainer.views[atIndex]; - this._utils.detachViewInContainer(parentView, boundElementIndex, atIndex); + var view = viewContainer.views[index]; + this._utils.detachViewInContainer(parentView, boundElementIndex, index); this._renderer.detachFragment(view.renderFragment); return wtfLeave(s, view.ref); } @@ -341,12 +341,12 @@ export class AppViewManager { } _destroyViewInContainer(parentView: viewModule.AppView, boundElementIndex: number, - atIndex: number) { + index: number) { var viewContainer = parentView.viewContainers[boundElementIndex]; - var view = viewContainer.views[atIndex]; + var view = viewContainer.views[index]; this._viewDehydrateRecurse(view); - this._utils.detachViewInContainer(parentView, boundElementIndex, atIndex); + this._utils.detachViewInContainer(parentView, boundElementIndex, index); if (view.viewOffset > 0) { // Case 1: a view that is part of another view. // Just detach the fragment diff --git a/modules/angular2/src/core/compiler/view_manager_utils.ts b/modules/angular2/src/core/compiler/view_manager_utils.ts index ed449728b3..cde24963b0 100644 --- a/modules/angular2/src/core/compiler/view_manager_utils.ts +++ b/modules/angular2/src/core/compiler/view_manager_utils.ts @@ -108,7 +108,7 @@ export class AppViewManagerUtils { // Misnomer: this method is attaching next to the view container. attachViewInContainer(parentView: viewModule.AppView, boundElementIndex: number, contextView: viewModule.AppView, contextBoundElementIndex: number, - atIndex: number, view: viewModule.AppView) { + index: number, view: viewModule.AppView) { if (isBlank(contextView)) { contextView = parentView; contextBoundElementIndex = boundElementIndex; @@ -119,7 +119,7 @@ export class AppViewManagerUtils { viewContainer = new viewModule.AppViewContainer(); parentView.viewContainers[boundElementIndex] = viewContainer; } - ListWrapper.insert(viewContainer.views, atIndex, view); + ListWrapper.insert(viewContainer.views, index, view); var elementInjector = contextView.elementInjectors[contextBoundElementIndex]; for (var i = view.rootElementInjectors.length - 1; i >= 0; i--) { @@ -131,14 +131,14 @@ export class AppViewManagerUtils { } detachViewInContainer(parentView: viewModule.AppView, boundElementIndex: number, - atIndex: number) { + index: number) { var viewContainer = parentView.viewContainers[boundElementIndex]; - var view = viewContainer.views[atIndex]; + var view = viewContainer.views[index]; parentView.elementInjectors[boundElementIndex].traverseAndSetQueriesAsDirty(); view.changeDetector.remove(); - ListWrapper.removeAt(viewContainer.views, atIndex); + ListWrapper.removeAt(viewContainer.views, index); for (var i = 0; i < view.rootElementInjectors.length; ++i) { var inj = view.rootElementInjectors[i]; inj.unlink(); @@ -148,13 +148,13 @@ export class AppViewManagerUtils { hydrateViewInContainer(parentView: viewModule.AppView, boundElementIndex: number, contextView: viewModule.AppView, contextBoundElementIndex: number, - atIndex: number, imperativelyCreatedBindings: ResolvedBinding[]) { + index: number, imperativelyCreatedBindings: ResolvedBinding[]) { if (isBlank(contextView)) { contextView = parentView; contextBoundElementIndex = boundElementIndex; } var viewContainer = parentView.viewContainers[boundElementIndex]; - var view = viewContainer.views[atIndex]; + var view = viewContainer.views[index]; var elementInjector = contextView.elementInjectors[contextBoundElementIndex]; var injector = isPresent(imperativelyCreatedBindings) ?