@@ -48,10 +48,16 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
48
48
$scope . $watch ( '$mdTabsCtrl.focusIndex' , handleFocusIndexChange ) ;
49
49
$scope . $watch ( '$mdTabsCtrl.offsetLeft' , handleOffsetChange ) ;
50
50
$scope . $watch ( '$mdTabsCtrl.hasContent' , handleHasContent ) ;
51
- angular . element ( $window ) . on ( 'resize' , function ( ) { $scope . $apply ( handleWindowResize ) ; } ) ;
52
- $timeout ( updateInkBarStyles , 0 , false ) ;
51
+ angular . element ( $window ) . on ( 'resize' , handleWindowResize ) ;
52
+ angular . element ( elements . paging ) . on ( 'DOMSubtreeModified' , updateInkBarStyles ) ;
53
53
$timeout ( updateHeightFromContent , 0 , false ) ;
54
54
$timeout ( adjustOffset ) ;
55
+ $scope . $on ( '$destroy' , cleanup ) ;
56
+ }
57
+
58
+ function cleanup ( ) {
59
+ angular . element ( $window ) . off ( 'resize' , handleWindowResize ) ;
60
+ angular . element ( elements . paging ) . off ( 'DOMSubtreeModified' , updateInkBarStyles ) ;
55
61
}
56
62
57
63
//-- Change handlers
@@ -100,7 +106,7 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
100
106
handleResizeWhenVisible . watcher = null ;
101
107
102
108
//-- we have to trigger our own $apply so that the DOM bindings will update
103
- $scope . $apply ( handleWindowResize ) ;
109
+ handleWindowResize ( ) ;
104
110
}
105
111
} , 0 , false ) ;
106
112
} ) ;
@@ -159,9 +165,11 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
159
165
}
160
166
161
167
function handleWindowResize ( ) {
162
- ctrl . lastSelectedIndex = $scope . selectedIndex ;
163
- ctrl . offsetLeft = fixOffset ( ctrl . offsetLeft ) ;
164
- $timeout ( updateInkBarStyles , 0 , false ) ;
168
+ $scope . $apply ( function ( ) {
169
+ ctrl . lastSelectedIndex = $scope . selectedIndex ;
170
+ ctrl . offsetLeft = fixOffset ( ctrl . offsetLeft ) ;
171
+ $timeout ( updateInkBarStyles , 0 , false ) ;
172
+ } ) ;
165
173
}
166
174
167
175
function removeTab ( tabData ) {
@@ -175,7 +183,6 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
175
183
ctrl . tabs [ $scope . selectedIndex ] && ctrl . tabs [ $scope . selectedIndex ] . scope . select ( ) ;
176
184
}
177
185
$timeout ( function ( ) {
178
- updateInkBarStyles ( ) ;
179
186
ctrl . offsetLeft = fixOffset ( ctrl . offsetLeft ) ;
180
187
} ) ;
181
188
}
@@ -270,7 +277,6 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
270
277
} ) ;
271
278
$scope . selectedIndex = ctrl . tabs . indexOf ( selectedItem ) ;
272
279
ctrl . focusIndex = ctrl . tabs . indexOf ( focusItem ) ;
273
- $timeout ( updateInkBarStyles , 0 , false ) ;
274
280
}
275
281
276
282
function incrementSelectedIndex ( inc , focus ) {
@@ -339,6 +345,7 @@ function MdTabsController ($scope, $element, $window, $timeout, $mdConstant, $md
339
345
}
340
346
341
347
function updateInkBarStyles ( ) {
348
+ if ( ! elements . tabs [ $scope . selectedIndex ] ) return ;
342
349
if ( ! ctrl . tabs . length ) return queue . push ( updateInkBarStyles ) ;
343
350
//-- if the element is not visible, we will not be able to calculate sizes until it is
344
351
//-- we should treat that as a resize event rather than just updating the ink bar
0 commit comments