I have an app using AngularJS and bootstrap that is causing me some problems. The main navigation is done through tabs and routing configured as follows:
app.config(function($routeProvider) {
$routeProvider.when("/", {
templateUrl: "index.html",
controller: "controllerIndex"
}).when("/pageone", {
templateUrl: "pageone.html",
controller: "controllerPageOne"
}).when("/pagetwo", {
templateUrl: "pagetwo.html",
controller: "controllerPageTwo"
});
return $routeProvider.otherwise({
templateUrl: "error.html"
});
});
In my pagetwo tab, I have two more tabs:
<tabset>
<tab heading="Metrics" active="tabs[0]" select="changeTab(0)">
<tab heading="Admin LDAP Search" active="tabs[1]" select="changeTab(1)">
</tabset>
As you can probably tell, I have been using a function changeTab and the "active" attribute to try and make the app remember what tab was selected on this page, even as the route changes. In controllerPageTwo, the relevant code is:
$scope.getCurrentTab = tabTracker.getCurrentTab()
$scope.tabs = tabTracker.getTabs()
$scope.changeTab = (tab) ->
tabTracker.setCurrentTab(tab)
The idea being that when the route changes to /pagetwo, the current (active) tab and the array of tabs will be pulled from a service, tabTracker. Then, the tab will be changed to that one by setting the proper array value to true, and the other to false. This works as expected, and is called when I change tabs as expected.
However, any time the route changes FROM /pagetwo, changeTab is called with a value of 1. This means that no matter what, when the route changes, the second tab will be the active one on return to this page.
Why is it being called with this max value? (I was messing around with three tabs, and had the same issue but it would call it with a value of 2). I know sometimes code is ran twice in the controllers, but I have no references to ng-controller anywhere except in my index.html.
Let me know if you need more information, I tried to include everything relevant without it getting too long.