@@ -66,6 +66,7 @@ export type MatTabBodyOriginState = 'left' | 'right';
66
66
export class MatTabBodyPortal extends CdkPortalOutlet implements OnInit , OnDestroy {
67
67
/** A subscription to events for when the tab body begins centering. */
68
68
private _centeringSub : Subscription ;
69
+ private _leavingSub : Subscription ;
69
70
70
71
constructor (
71
72
_componentFactoryResolver : ComponentFactoryResolver ,
@@ -84,17 +85,23 @@ export class MatTabBodyPortal extends CdkPortalOutlet implements OnInit, OnDestr
84
85
if ( ! this . hasAttached ( ) ) {
85
86
this . attach ( this . _host . _content ) ;
86
87
}
87
- } else {
88
- this . detach ( ) ;
89
88
}
90
89
} ) ;
90
+
91
+ this . _leavingSub = this . _host . _afterLeavingCenter . subscribe ( ( ) => {
92
+ this . detach ( ) ;
93
+ } ) ;
91
94
}
92
95
93
96
/** Clean up centering subscription. */
94
97
ngOnDestroy ( ) : void {
95
98
if ( this . _centeringSub && ! this . _centeringSub . closed ) {
96
99
this . _centeringSub . unsubscribe ( ) ;
97
100
}
101
+
102
+ if ( this . _leavingSub && ! this . _leavingSub . closed ) {
103
+ this . _leavingSub . unsubscribe ( ) ;
104
+ }
98
105
}
99
106
}
100
107
@@ -139,6 +146,9 @@ export class MatTabBody implements OnInit {
139
146
/** Event emitted before the centering of the tab begins. */
140
147
@Output ( ) _beforeCentering : EventEmitter < boolean > = new EventEmitter < boolean > ( ) ;
141
148
149
+ /** Event emitted before the centering of the tab begins. */
150
+ @Output ( ) _afterLeavingCenter : EventEmitter < boolean > = new EventEmitter < boolean > ( ) ;
151
+
142
152
/** Event emitted when the tab completes its animation towards the center. */
143
153
@Output ( ) _onCentered : EventEmitter < void > = new EventEmitter < void > ( true ) ;
144
154
@@ -198,6 +208,10 @@ export class MatTabBody implements OnInit {
198
208
if ( this . _isCenterPosition ( e . toState ) && this . _isCenterPosition ( this . _position ) ) {
199
209
this . _onCentered . emit ( ) ;
200
210
}
211
+
212
+ if ( this . _isCenterPosition ( e . fromState ) && ! this . _isCenterPosition ( this . _position ) ) {
213
+ this . _afterLeavingCenter . emit ( ) ;
214
+ }
201
215
}
202
216
203
217
/** The text direction of the containing app. */
0 commit comments