File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 77import { PortalHostDirective } from '@angular2-material/core/portal/portal-directives' ;
88import { PromiseCompleter } from '@angular2-material/core/async/promise-completer' ;
99import { MdDialogConfig } from './dialog-config' ;
10+ import { MdDialogContentAlreadyAttachedError } from './dialog-errors' ;
1011
1112
1213/**
@@ -49,20 +50,24 @@ export class MdDialogContainer extends BasePortalHost implements AfterViewInit {
4950
5051 this . _deferredAttachPortal = null ;
5152 this . _deferredAttachCompleter = null ;
52- } ) ;
53+ } , ( ) => this . _deferredAttachCompleter . reject ( ) ) ;
5354 }
5455 }
5556
5657 /** Attach a portal as content to this dialog container. */
5758 attachComponentPortal < T > ( portal : ComponentPortal < T > ) : Promise < ComponentRef < T > > {
5859 if ( this . _portalHost ) {
60+ if ( this . _portalHost . hasAttached ( ) ) {
61+ throw new MdDialogContentAlreadyAttachedError ( ) ;
62+ }
63+
5964 return this . _portalHost . attachComponentPortal ( portal ) ;
6065 } else {
6166 // The @ViewChild query for the portalHost is not resolved until AfterViewInit, but this
6267 // function may be called before this lifecycle event. As such, we defer the attachment of
6368 // the portal until AfterViewInit.
6469 if ( this . _deferredAttachCompleter ) {
65- this . _deferredAttachCompleter . reject ( ) ;
70+ throw new MdDialogContentAlreadyAttachedError ( ) ;
6671 }
6772
6873 this . _deferredAttachPortal = portal ;
Original file line number Diff line number Diff line change 1+ import { MdError } from '@angular2-material/core/errors/error' ;
2+
3+ /** Exception thrown when a ComponentPortal is attached to a DomPortalHost without an origin. */
4+ export class MdDialogContentAlreadyAttachedError extends MdError {
5+ constructor ( ) {
6+ super ( 'Attempting to attach dialog content after content is already attached' ) ;
7+ }
8+ }
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ describe('MdDialog', () => {
8989
9090/** Runs the necessary detectChanges for a dialog to complete its opening. */
9191function detectChangesForDialogOpen ( fixture : ComponentFixture < ComponentWithChildViewContainer > ) {
92- // TODO(jelbourn): figure out why the test zone is "stable" when where are still pending
92+ // TODO(jelbourn): figure out why the test zone is "stable" when there are still pending
9393 // tasks, such that we have to use `setTimeout` to run the second round of change detection.
9494 // Two rounds of change detection are necessary: one to *create* the dialog container, and
9595 // another to cause the lifecycle events of the container to run and load the dialog content.
You can’t perform that action at this time.
0 commit comments