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 7
7
import { PortalHostDirective } from '@angular2-material/core/portal/portal-directives' ;
8
8
import { PromiseCompleter } from '@angular2-material/core/async/promise-completer' ;
9
9
import { MdDialogConfig } from './dialog-config' ;
10
+ import { MdDialogContentAlreadyAttachedError } from './dialog-errors' ;
10
11
11
12
12
13
/**
@@ -49,20 +50,24 @@ export class MdDialogContainer extends BasePortalHost implements AfterViewInit {
49
50
50
51
this . _deferredAttachPortal = null ;
51
52
this . _deferredAttachCompleter = null ;
52
- } ) ;
53
+ } , ( ) => this . _deferredAttachCompleter . reject ( ) ) ;
53
54
}
54
55
}
55
56
56
57
/** Attach a portal as content to this dialog container. */
57
58
attachComponentPortal < T > ( portal : ComponentPortal < T > ) : Promise < ComponentRef < T > > {
58
59
if ( this . _portalHost ) {
60
+ if ( this . _portalHost . hasAttached ( ) ) {
61
+ throw new MdDialogContentAlreadyAttachedError ( ) ;
62
+ }
63
+
59
64
return this . _portalHost . attachComponentPortal ( portal ) ;
60
65
} else {
61
66
// The @ViewChild query for the portalHost is not resolved until AfterViewInit, but this
62
67
// function may be called before this lifecycle event. As such, we defer the attachment of
63
68
// the portal until AfterViewInit.
64
69
if ( this . _deferredAttachCompleter ) {
65
- this . _deferredAttachCompleter . reject ( ) ;
70
+ throw new MdDialogContentAlreadyAttachedError ( ) ;
66
71
}
67
72
68
73
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', () => {
89
89
90
90
/** Runs the necessary detectChanges for a dialog to complete its opening. */
91
91
function 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
93
93
// tasks, such that we have to use `setTimeout` to run the second round of change detection.
94
94
// Two rounds of change detection are necessary: one to *create* the dialog container, and
95
95
// 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