From 116b64de25e3fe2505d358b2ef2e8496096a62f9 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Thu, 16 Jul 2015 15:17:52 -0700 Subject: [PATCH] fix(view_manager): allow to create host views even if there is an embedded view at the same place. --- .../angular2/src/core/compiler/view_manager.ts | 3 ++- .../test/core/compiler/view_manager_spec.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/angular2/src/core/compiler/view_manager.ts b/modules/angular2/src/core/compiler/view_manager.ts index 94cbab48c4..4064088feb 100644 --- a/modules/angular2/src/core/compiler/view_manager.ts +++ b/modules/angular2/src/core/compiler/view_manager.ts @@ -188,7 +188,8 @@ export class AppViewManager { var embeddedFragmentView = contextView.getNestedView(contextBoundElementIndex); var view; - if (isPresent(embeddedFragmentView) && !embeddedFragmentView.hydrated()) { + if (protoView.type === ViewType.EMBEDDED && isPresent(embeddedFragmentView) && + !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); diff --git a/modules/angular2/test/core/compiler/view_manager_spec.ts b/modules/angular2/test/core/compiler/view_manager_spec.ts index e2a0ebd417..cc3daf844d 100644 --- a/modules/angular2/test/core/compiler/view_manager_spec.ts +++ b/modules/angular2/test/core/compiler/view_manager_spec.ts @@ -300,6 +300,22 @@ export function main() { }); + describe('create a host view', () => { + + it('should always create a new view and not use the embedded view', () => { + var newHostPv = createHostPv([createNestedElBinder(createComponentPv())]); + var newHostView = + internalView(manager.createViewInContainer(vcRef, 0, wrapPv(newHostPv), null)); + expect(newHostView.proto).toBe(newHostPv); + expect(newHostView).not.toBe(hostView.views[2]); + expect(viewListener.spy('viewCreated')).toHaveBeenCalledWith(newHostView); + expect(renderer.spy('createView')) + .toHaveBeenCalledWith(newHostPv.mergeMapping.renderProtoViewRef, + newHostPv.mergeMapping.renderFragmentCount); + }); + + }); + }); });