Skip to content

Commit

Permalink
Revert "fix(portal): detect changes for portal hostview while before …
Browse files Browse the repository at this point in the history
…attaching. (angular#4370)"

This reverts commit 28d2ddd.
  • Loading branch information
jelbourn committed Jun 14, 2017
1 parent d3d6d26 commit bdae634
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 33 deletions.
10 changes: 7 additions & 3 deletions src/lib/core/portal/dom-portal-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@ export class DomPortalHost extends BasePortalHost {
*/
attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T> {
let componentFactory = this._componentFactoryResolver.resolveComponentFactory(portal.component);
let componentRef = componentFactory.create(portal.injector || this._defaultInjector);
componentRef.hostView.detectChanges();
let componentRef: ComponentRef<T>;

// 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) {
portal.viewContainerRef.insert(componentRef.hostView);
componentRef = portal.viewContainerRef.createComponent(
componentFactory,
portal.viewContainerRef.length,
portal.injector || portal.viewContainerRef.parentInjector);

this.setDisposeFn(() => componentRef.destroy());
} else {
componentRef = componentFactory.create(portal.injector || this._defaultInjector);
this._appRef.attachView(componentRef.hostView);
this.setDisposeFn(() => {
this._appRef.detachView(componentRef.hostView);
Expand Down
22 changes: 1 addition & 21 deletions src/lib/core/portal/portal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,6 @@ describe('Portals', () => {

expect(spy).toHaveBeenCalled();
});

it('should run change detection in the created component when a ComponentPortal is attached',
() => {
host.attach(new ComponentPortal(ComponentWithBoundVariable, someViewContainerRef));
expect(someDomElement.textContent).toContain('initial value');
});
});
});

Expand Down Expand Up @@ -410,15 +404,6 @@ class ArbitraryViewContainerRefComponent {
constructor(public viewContainerRef: ViewContainerRef, public injector: Injector) { }
}

/** Simple component with a bound variable in the template */
@Component({
selector: 'bound-text',
template: '<p>{{text}}</p>'
})
class ComponentWithBoundVariable {
text: string = 'initial value';
}


/** Test-bed component that contains a portal host and a couple of template portals. */
@Component({
Expand Down Expand Up @@ -468,12 +453,7 @@ class PortalTestApp {

// Create a real (non-test) NgModule as a workaround for
// https://github.com/angular/angular/issues/10760
const TEST_COMPONENTS = [
PortalTestApp,
ArbitraryViewContainerRefComponent,
PizzaMsg,
ComponentWithBoundVariable
];
const TEST_COMPONENTS = [PortalTestApp, ArbitraryViewContainerRefComponent, PizzaMsg];
@NgModule({
imports: [CommonModule, PortalModule],
exports: TEST_COMPONENTS,
Expand Down
16 changes: 8 additions & 8 deletions src/lib/datepicker/datepicker-content.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<md-calendar cdkTrapFocus
[id]="datepicker?.id"
[startAt]="datepicker?.startAt"
[startView]="datepicker?.startView"
[minDate]="datepicker?._minDate"
[maxDate]="datepicker?._maxDate"
[dateFilter]="datepicker?._dateFilter"
[selected]="datepicker?._selected"
(selectedChange)="datepicker?._selectAndClose($event)">
[id]="datepicker.id"
[startAt]="datepicker.startAt"
[startView]="datepicker.startView"
[minDate]="datepicker._minDate"
[maxDate]="datepicker._maxDate"
[dateFilter]="datepicker._dateFilter"
[selected]="datepicker._selected"
(selectedChange)="datepicker._selectAndClose($event)">
</md-calendar>
2 changes: 1 addition & 1 deletion src/lib/datepicker/datepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let datepickerUid = 0;
styleUrls: ['datepicker-content.css'],
host: {
'class': 'mat-datepicker-content',
'[class.mat-datepicker-content-touch]': 'datepicker?.touchUi',
'[class.mat-datepicker-content-touch]': 'datepicker.touchUi',
'(keydown)': '_handleKeydown($event)',
},
encapsulation: ViewEncapsulation.None,
Expand Down

0 comments on commit bdae634

Please sign in to comment.