From 4d186ffc38ba6578c7dd62b5a71ad3c6ebfffbe0 Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Tue, 2 May 2017 15:52:06 -0700 Subject: [PATCH] fix(portal): detect changes for portal hostview while before attaching. --- src/lib/core/portal/dom-portal-host.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/lib/core/portal/dom-portal-host.ts b/src/lib/core/portal/dom-portal-host.ts index 7a2ebf360779..c2244fd4d551 100644 --- a/src/lib/core/portal/dom-portal-host.ts +++ b/src/lib/core/portal/dom-portal-host.ts @@ -29,21 +29,17 @@ export class DomPortalHost extends BasePortalHost { */ attachComponentPortal(portal: ComponentPortal): ComponentRef { let componentFactory = this._componentFactoryResolver.resolveComponentFactory(portal.component); - let componentRef: ComponentRef; + let componentRef = componentFactory.create(portal.injector || this._defaultInjector); + componentRef.hostView.detectChanges(); // If the portal specifies a ViewContainerRef, we will use that as the attachment point // for the component (in terms of Angular's component tree, not rendering). // When the ViewContainerRef is missing, we use the factory to create the component directly // and then manually attach the view to the application. if (portal.viewContainerRef) { - componentRef = portal.viewContainerRef.createComponent( - componentFactory, - portal.viewContainerRef.length, - portal.injector || portal.viewContainerRef.parentInjector); - + portal.viewContainerRef.insert(componentRef.hostView); this.setDisposeFn(() => componentRef.destroy()); } else { - componentRef = componentFactory.create(portal.injector || this._defaultInjector); this._appRef.attachView(componentRef.hostView); this.setDisposeFn(() => { this._appRef.detachView(componentRef.hostView);