@@ -14,6 +14,7 @@ import {
14
14
HostListener ,
15
15
Input ,
16
16
NgModule ,
17
+ OnDestroy ,
17
18
Output ,
18
19
QueryList ,
19
20
TemplateRef ,
@@ -66,7 +67,7 @@ export class IgxTabTemplateDirective {
66
67
}
67
68
` ]
68
69
} )
69
- export class IgxBottomNavComponent implements AfterViewInit {
70
+ export class IgxBottomNavComponent implements AfterViewInit , OnDestroy {
70
71
71
72
/**
72
73
* Gets the `IgxTabComponent` elements in the tab bar component.
@@ -172,32 +173,44 @@ export class IgxBottomNavComponent implements AfterViewInit {
172
173
*/
173
174
public ngAfterViewInit ( ) {
174
175
// initial selection
175
- this . _navigationEndSubscription = this . router . events . pipe (
176
- filter ( event => event instanceof NavigationEnd ) ) . subscribe ( ( args ) => {
177
- const panelsArray = this . panels . toArray ( ) ;
178
- for ( let i = 0 ; i < panelsArray . length ; i ++ ) {
179
- if ( panelsArray [ i ] . routerLinkDirective &&
180
- this . router . url . startsWith ( panelsArray [ i ] . routerLinkDirective . urlTree . toString ( ) ) ) {
181
- panelsArray [ i ] . selectAndUpdateRoute ( false ) ;
182
- break ;
183
- }
184
- }
185
- this . _navigationEndSubscription . unsubscribe ( ) ;
186
- }
187
- ) ;
188
-
189
176
setTimeout ( ( ) => {
177
+ this . navigationEndHandler ( this ) ;
190
178
if ( this . selectedIndex === - 1 ) {
191
179
const selectablePanels = this . panels . filter ( ( p ) => ! p . disabled ) ;
192
180
const panel = selectablePanels [ 0 ] ;
193
-
194
181
if ( panel ) {
195
182
panel . select ( ) ;
196
183
}
197
184
}
185
+ this . _navigationEndSubscription = this . router . events . pipe (
186
+ filter ( event => event instanceof NavigationEnd ) ) . subscribe ( ( ) => {
187
+ this . navigationEndHandler ( this ) ;
188
+ }
189
+ ) ;
198
190
} , 0 ) ;
199
191
}
200
192
193
+ /**
194
+ *@hidden
195
+ */
196
+ public navigationEndHandler ( bottomNavControl : IgxBottomNavComponent ) {
197
+ const panelsArray = bottomNavControl . panels . toArray ( ) ;
198
+ for ( let i = 0 ; i < panelsArray . length ; i ++ ) {
199
+ if ( panelsArray [ i ] . routerLinkDirective &&
200
+ bottomNavControl . router . url . startsWith ( panelsArray [ i ] . routerLinkDirective . urlTree . toString ( ) ) ) {
201
+ panelsArray [ i ] . _selectAndEmitEvent ( ) ;
202
+ break ;
203
+ }
204
+ }
205
+ }
206
+
207
+ /**
208
+ *@hidden
209
+ */
210
+ public ngOnDestroy ( ) {
211
+ this . _navigationEndSubscription . unsubscribe ( ) ;
212
+ }
213
+
201
214
/**
202
215
*@hidden
203
216
*/
@@ -413,20 +426,21 @@ export class IgxTabPanelComponent implements AfterContentInit, AfterViewChecked
413
426
* @memberof IgxTabPanelComponent
414
427
*/
415
428
public select ( ) {
416
- this . selectAndUpdateRoute ( true ) ;
429
+ if ( this . disabled || this . _tabBar . selectedIndex === this . index ) {
430
+ return ;
431
+ }
432
+ if ( this . routerLinkDirective ) {
433
+ this . routerLinkDirective . onClick ( ) ;
434
+ } else {
435
+ this . _selectAndEmitEvent ( ) ;
436
+ }
417
437
}
418
438
419
439
/**
420
440
*@hidden
421
441
*/
422
- public selectAndUpdateRoute ( updateRoute : boolean ) {
423
- if ( this . disabled || this . _tabBar . selectedIndex === this . index ) {
424
- return ;
425
- }
442
+ public _selectAndEmitEvent ( ) {
426
443
this . isSelected = true ;
427
- if ( updateRoute && this . routerLinkDirective ) {
428
- this . routerLinkDirective . onClick ( ) ;
429
- }
430
444
this . _tabBar . onTabSelected . emit ( { tab : this . _tabBar . tabs . toArray ( ) [ this . index ] , panel : this } ) ;
431
445
}
432
446
}
0 commit comments