()
| 372 | } |
| 373 | |
| 374 | ngAfterContentInit() { |
| 375 | this._subscribeToAllTabChanges(); |
| 376 | this._subscribeToTabLabels(); |
| 377 | |
| 378 | // Subscribe to changes in the amount of tabs, in order to be |
| 379 | // able to re-render the content as new tabs are added or removed. |
| 380 | this._tabsSubscription = this._tabs.changes.subscribe(() => { |
| 381 | const indexToSelect = this._clampTabIndex(this._indexToSelect); |
| 382 | |
| 383 | // Maintain the previously-selected tab if a new tab is added or removed and there is no |
| 384 | // explicit change that selects a different tab. |
| 385 | if (indexToSelect === this._selectedIndex) { |
| 386 | const tabs = this._tabs.toArray(); |
| 387 | let selectedTab: MatTab | undefined; |
| 388 | |
| 389 | for (let i = 0; i < tabs.length; i++) { |
| 390 | if (tabs[i].isActive) { |
| 391 | // Assign both to the `_indexToSelect` and `_selectedIndex` so we don't fire a changed |
| 392 | // event, otherwise the consumer may end up in an infinite loop in some edge cases like |
| 393 | // adding a tab within the `selectedIndexChange` event. |
| 394 | this._indexToSelect = this._selectedIndex = i; |
| 395 | this._lastFocusedTabIndex = null; |
| 396 | selectedTab = tabs[i]; |
| 397 | break; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | // If we haven't found an active tab and a tab exists at the selected index, it means |
| 402 | // that the active tab was swapped out. Since this won't be picked up by the rendering |
| 403 | // loop in `ngAfterContentChecked`, we need to sync it up manually. |
| 404 | if (!selectedTab && tabs[indexToSelect]) { |
| 405 | Promise.resolve().then(() => { |
| 406 | tabs[indexToSelect].isActive = true; |
| 407 | this.selectedTabChange.emit(this._createChangeEvent(indexToSelect)); |
| 408 | }); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | this._changeDetectorRef.markForCheck(); |
| 413 | }); |
| 414 | } |
| 415 | |
| 416 | ngAfterViewInit() { |
| 417 | this._tabBodySubscription = this._tabBodies!.changes.subscribe(() => this._bodyCentered(true)); |
nothing calls this directly
no test coverage detected