@@ -106,7 +106,7 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
106
106
private _overlay = inject ( Overlay ) ;
107
107
private _dir = inject ( Directionality , { optional : true } ) ;
108
108
109
- private _overlayRef : OverlayRef ;
109
+ private _overlayRef : OverlayRef | undefined ;
110
110
private _templatePortal : TemplatePortal ;
111
111
private _backdropSubscription = Subscription . EMPTY ;
112
112
private _attachSubscription = Subscription . EMPTY ;
@@ -251,7 +251,7 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
251
251
252
252
/** The associated overlay reference. */
253
253
get overlayRef ( ) : OverlayRef {
254
- return this . _overlayRef ;
254
+ return this . _overlayRef ! ;
255
255
}
256
256
257
257
/** The element's layout direction. */
@@ -264,16 +264,13 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
264
264
this . _detachSubscription . unsubscribe ( ) ;
265
265
this . _backdropSubscription . unsubscribe ( ) ;
266
266
this . _positionSubscription . unsubscribe ( ) ;
267
-
268
- if ( this . _overlayRef ) {
269
- this . _overlayRef . dispose ( ) ;
270
- }
267
+ this . _overlayRef ?. dispose ( ) ;
271
268
}
272
269
273
270
ngOnChanges ( changes : SimpleChanges ) {
274
271
if ( this . _position ) {
275
272
this . _updatePositionStrategy ( this . _position ) ;
276
- this . _overlayRef . updateSize ( {
273
+ this . _overlayRef ? .updateSize ( {
277
274
width : this . width ,
278
275
minWidth : this . minWidth ,
279
276
height : this . height ,
@@ -286,7 +283,7 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
286
283
}
287
284
288
285
if ( changes [ 'open' ] ) {
289
- this . open ? this . _attachOverlay ( ) : this . _detachOverlay ( ) ;
286
+ this . open ? this . attachOverlay ( ) : this . detachOverlay ( ) ;
290
287
}
291
288
}
292
289
@@ -304,7 +301,7 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
304
301
305
302
if ( event . keyCode === ESCAPE && ! this . disableClose && ! hasModifierKey ( event ) ) {
306
303
event . preventDefault ( ) ;
307
- this . _detachOverlay ( ) ;
304
+ this . detachOverlay ( ) ;
308
305
}
309
306
} ) ;
310
307
@@ -411,21 +408,21 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
411
408
return null ;
412
409
}
413
410
414
- /** Attaches the overlay and subscribes to backdrop clicks if backdrop exists */
415
- private _attachOverlay ( ) {
411
+ /** Attaches the overlay. */
412
+ attachOverlay ( ) {
416
413
if ( ! this . _overlayRef ) {
417
414
this . _createOverlay ( ) ;
418
415
} else {
419
416
// Update the overlay size, in case the directive's inputs have changed
420
417
this . _overlayRef . getConfig ( ) . hasBackdrop = this . hasBackdrop ;
421
418
}
422
419
423
- if ( ! this . _overlayRef . hasAttached ( ) ) {
424
- this . _overlayRef . attach ( this . _templatePortal ) ;
420
+ if ( ! this . _overlayRef ! . hasAttached ( ) ) {
421
+ this . _overlayRef ! . attach ( this . _templatePortal ) ;
425
422
}
426
423
427
424
if ( this . hasBackdrop ) {
428
- this . _backdropSubscription = this . _overlayRef . backdropClick ( ) . subscribe ( event => {
425
+ this . _backdropSubscription = this . _overlayRef ! . backdropClick ( ) . subscribe ( event => {
429
426
this . backdropClick . emit ( event ) ;
430
427
} ) ;
431
428
} else {
@@ -447,16 +444,16 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
447
444
}
448
445
} ) ;
449
446
}
450
- }
451
447
452
- /** Detaches the overlay and unsubscribes to backdrop clicks if backdrop exists */
453
- private _detachOverlay ( ) {
454
- if ( this . _overlayRef ) {
455
- this . _overlayRef . detach ( ) ;
456
- }
448
+ this . open = true ;
449
+ }
457
450
451
+ /** Detaches the overlay. */
452
+ detachOverlay ( ) {
453
+ this . _overlayRef ?. detach ( ) ;
458
454
this . _backdropSubscription . unsubscribe ( ) ;
459
455
this . _positionSubscription . unsubscribe ( ) ;
456
+ this . open = false ;
460
457
}
461
458
}
462
459
0 commit comments