@@ -35,8 +35,10 @@ import 'tab_change_event.dart';
3535 // TODO(google): Change to `Visibility.local` to reduce code size.
3636 visibility: Visibility .all,
3737)
38- class MaterialTabPanelComponent {
38+ class MaterialTabPanelComponent implements AfterContentInit {
3939 final ChangeDetectorRef _changeDetector;
40+ bool _initialzed = false ;
41+ Tab _previousActiveTab;
4042
4143 /// Stream of [TabChangeEvent] instances, published before the tab has
4244 /// changed.
@@ -78,10 +80,22 @@ class MaterialTabPanelComponent {
7880
7981 MaterialTabPanelComponent (this ._changeDetector);
8082
83+ @override
84+ void ngAfterContentInit () {
85+ _initialzed = true ;
86+ _initTabs ();
87+ }
88+
8189 @ContentChildren (Tab )
82- set tabs (QueryList <Tab > tabQuery) {
83- final previousActiveTab = (_tabs != null ) ? _activeTab : null ;
84- _tabs = new List .from (tabQuery);
90+ set tabs (List <Tab > tabs) {
91+ _previousActiveTab = (_tabs != null ) ? _activeTab : null ;
92+ _tabs = tabs;
93+ // TODO(google): Remove if setting of content children occur after
94+ // child is initialized.
95+ if (_initialzed) _initTabs ();
96+ }
97+
98+ void _initTabs () {
8599 _tabLabels = _tabs.map ((t) => t.label).toList ();
86100 _tabIds = _tabs.map ((t) => t.tabId).toList ();
87101
@@ -90,8 +104,9 @@ class MaterialTabPanelComponent {
90104 scheduleMicrotask (() {
91105 _changeDetector.markForCheck (); // call early so we can return early.
92106 // Look for the previously active tab.
93- if (previousActiveTab != null ) {
94- _activeTabIndex = _tabs.indexOf (previousActiveTab);
107+ if (_previousActiveTab != null ) {
108+ _activeTabIndex = _tabs.indexOf (_previousActiveTab);
109+ _previousActiveTab = null ;
95110 if (_activeTabIndex == - 1 ) {
96111 // Couldn't find previous tab. Just activate the first tab.
97112 _activeTabIndex = 0 ;
0 commit comments