Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit b38d928

Browse files
Sam Elliott De La Torre Babákara
authored andcommitted
fix(nav-bar): null check tabs when updating nav-bar (#9071)
1 parent d8263f2 commit b38d928

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/components/navBar/navBar.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ MdNavBarController.prototype._initTabs = function() {
222222
MdNavBarController.prototype._updateTabs = function(newValue, oldValue) {
223223
var self = this;
224224
var tabs = this._getTabs();
225+
226+
// this._getTabs can return null if nav-bar has not yet been initialized
227+
if(!tabs)
228+
return;
229+
225230
var oldIndex = -1;
226231
var newIndex = -1;
227232
var newTab = this._getTabByName(newValue);
@@ -266,11 +271,12 @@ MdNavBarController.prototype._updateInkBarStyles = function(tab, newIndex, oldIn
266271
* @private
267272
*/
268273
MdNavBarController.prototype._getTabs = function() {
269-
var linkArray = Array.prototype.slice.call(
270-
this._navBarEl.querySelectorAll('.md-nav-item'));
271-
return linkArray.map(function(el) {
272-
return angular.element(el).controller('mdNavItem');
273-
});
274+
var controllers = Array.prototype.slice.call(
275+
this._navBarEl.querySelectorAll('.md-nav-item'))
276+
.map(function(el) {
277+
return angular.element(el).controller('mdNavItem')
278+
});
279+
return controllers.indexOf(undefined) ? controllers : null;
274280
};
275281

276282
/**

src/components/navBar/navBar.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ describe('mdNavBar', function() {
175175
expect(getTab('tab2').attr('ui-sref-opts'))
176176
.toBe('{"reload":true,"notify":true}');
177177
});
178+
179+
it('does not update tabs if tab controller is undefined', function() {
180+
$scope.selectedTabRoute = 'tab1';
181+
182+
spyOn(Object.getPrototypeOf(ctrl), '_updateInkBarStyles');
183+
spyOn(Object.getPrototypeOf(ctrl), '_getTabs').and.returnValue(null);
184+
createTabs();
185+
186+
expect(ctrl._updateInkBarStyles)
187+
.not.toHaveBeenCalled();
188+
});
178189
});
179190

180191
describe('inkbar', function() {

0 commit comments

Comments
 (0)