diff --git a/src/tabs/tabs.js b/src/tabs/tabs.js index e79b9187d7..adf3c5c7a6 100644 --- a/src/tabs/tabs.js +++ b/src/tabs/tabs.js @@ -55,9 +55,15 @@ angular.module('ui.bootstrap.tabs', []) }; ctrl.removeTab = function removeTab(tab) { - var index = findTabIndex(tab.index); + var index; + for (var i = 0; i < ctrl.tabs.length; i++) { + if (ctrl.tabs[i].tab === tab) { + index = i; + break; + } + } - if (tab.index === ctrl.active) { + if (ctrl.tabs[index].index === ctrl.active) { var newActiveTabIndex = index === ctrl.tabs.length - 1 ? index - 1 : index + 1 % ctrl.tabs.length; ctrl.select(newActiveTabIndex); diff --git a/src/tabs/test/tabs.spec.js b/src/tabs/test/tabs.spec.js index c18e9ea258..f2e7642e11 100644 --- a/src/tabs/test/tabs.spec.js +++ b/src/tabs/test/tabs.spec.js @@ -670,6 +670,31 @@ describe('tabs', function() { expect(contents().eq(1)).toHaveClass('active'); })); + it('should use updated index in tab', inject(function($controller, $compile, $rootScope) { + scope = $rootScope.$new(); + elm = $compile('Hellocontent {{i}}')(scope); + scope.$apply(); + + scope.$apply('list = [1,2,3]'); + expectTitles(['1', 'tab 1', 'tab 2', 'tab 3']); + expectContents(['Hello', 'content 1', 'content 2', 'content 3']); + + // Remove middle "tab 2" tab + scope.$apply('list = [1,3]'); + expectTitles(['1', 'tab 1', 'tab 3']); + expectContents(['Hello', 'content 1', 'content 3']); + + // Remove last "tab 3" tab + scope.$apply('list = [1]'); + expectTitles(['1', 'tab 1']); + expectContents(['Hello', 'content 1']); + + // Select first tab + titles().find('> a').eq(0).click(); + expect(titles().eq(0)).toHaveClass('active'); + expect(contents().eq(0)).toHaveClass('active'); + })); + it('should not select tabs when being destroyed', inject(function($controller, $compile, $rootScope) { var selectList = [], deselectList = [],