9
9
Input ,
10
10
OnDestroy ,
11
11
Output ,
12
- ElementRef
12
+ ElementRef ,
13
+ OnChanges ,
14
+ SimpleChanges ,
13
15
} from '@angular/core' ;
14
16
import { Overlay , OVERLAY_PROVIDERS } from './overlay' ;
15
17
import { OverlayRef } from './overlay-ref' ;
@@ -58,15 +60,12 @@ export class OverlayOrigin {
58
60
selector : '[cdk-connected-overlay], [connected-overlay]' ,
59
61
exportAs : 'cdkConnectedOverlay'
60
62
} )
61
- export class ConnectedOverlayDirective implements OnDestroy {
63
+ export class ConnectedOverlayDirective implements OnDestroy , OnChanges {
62
64
private _overlayRef : OverlayRef ;
63
65
private _templatePortal : TemplatePortal ;
64
- private _open = false ;
65
66
private _hasBackdrop = false ;
66
67
private _backdropSubscription : Subscription ;
67
68
private _positionSubscription : Subscription ;
68
- private _offsetX : number = 0 ;
69
- private _offsetY : number = 0 ;
70
69
private _position : ConnectedPositionStrategy ;
71
70
72
71
/** Origin for the connected overlay. */
@@ -76,30 +75,10 @@ export class ConnectedOverlayDirective implements OnDestroy {
76
75
@Input ( ) positions : ConnectionPositionPair [ ] ;
77
76
78
77
/** The offset in pixels for the overlay connection point on the x-axis */
79
- @Input ( )
80
- get offsetX ( ) : number {
81
- return this . _offsetX ;
82
- }
83
-
84
- set offsetX ( offsetX : number ) {
85
- this . _offsetX = offsetX ;
86
- if ( this . _position ) {
87
- this . _position . withOffsetX ( offsetX ) ;
88
- }
89
- }
78
+ @Input ( ) offsetX : number = 0 ;
90
79
91
80
/** The offset in pixels for the overlay connection point on the y-axis */
92
- @Input ( )
93
- get offsetY ( ) {
94
- return this . _offsetY ;
95
- }
96
-
97
- set offsetY ( offsetY : number ) {
98
- this . _offsetY = offsetY ;
99
- if ( this . _position ) {
100
- this . _position . withOffsetY ( offsetY ) ;
101
- }
102
- }
81
+ @Input ( ) offsetY : number = 0 ;
103
82
104
83
/** The width of the overlay panel. */
105
84
@Input ( ) width : number | string ;
@@ -116,6 +95,9 @@ export class ConnectedOverlayDirective implements OnDestroy {
116
95
/** The custom class to be set on the backdrop element. */
117
96
@Input ( ) backdropClass : string ;
118
97
98
+ /** Whether the overlay is open. */
99
+ @Input ( ) open : boolean = false ;
100
+
119
101
/** Whether or not the overlay should attach a backdrop. */
120
102
@Input ( )
121
103
get hasBackdrop ( ) {
@@ -126,16 +108,6 @@ export class ConnectedOverlayDirective implements OnDestroy {
126
108
this . _hasBackdrop = coerceBooleanProperty ( value ) ;
127
109
}
128
110
129
- @Input ( )
130
- get open ( ) {
131
- return this . _open ;
132
- }
133
-
134
- set open ( value : boolean ) {
135
- value ? this . _attachOverlay ( ) : this . _detachOverlay ( ) ;
136
- this . _open = value ;
137
- }
138
-
139
111
/** Event emitted when the backdrop is clicked. */
140
112
@Output ( ) backdropClick = new EventEmitter < void > ( ) ;
141
113
@@ -172,6 +144,20 @@ export class ConnectedOverlayDirective implements OnDestroy {
172
144
this . _destroyOverlay ( ) ;
173
145
}
174
146
147
+ ngOnChanges ( changes : SimpleChanges ) {
148
+ if ( changes [ 'open' ] ) {
149
+ changes [ 'open' ] . currentValue ? this . _attachOverlay ( ) : this . _detachOverlay ( ) ;
150
+ }
151
+
152
+ if ( changes [ 'offsetX' ] && this . _position ) {
153
+ this . _position . withOffsetX ( changes [ 'offsetX' ] . currentValue ) ;
154
+ }
155
+
156
+ if ( changes [ 'offsetY' ] && this . _position ) {
157
+ this . _position . withOffsetY ( changes [ 'offsetY' ] . currentValue ) ;
158
+ }
159
+ }
160
+
175
161
/** Creates an overlay */
176
162
private _createOverlay ( ) {
177
163
if ( ! this . positions || ! this . positions . length ) {
0 commit comments