From 0e3cda8ff78816a3dd1c4845f024dbc42bd32483 Mon Sep 17 00:00:00 2001 From: John Wilkinson Date: Thu, 26 Feb 2015 13:01:02 -0500 Subject: [PATCH] prevent race condition that incorrectly redirects to the default tab sometimes --- src/ui-router-tabs.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ui-router-tabs.js b/src/ui-router-tabs.js index 3fe0f81..0914805 100644 --- a/src/ui-router-tabs.js +++ b/src/ui-router-tabs.js @@ -88,13 +88,15 @@ angular.module('ui.router.tabs').directive('tabs', ['$rootScope', '$state', }; // initialise tabs when creating the directive - $scope.update_tabs(); - - // if none are active, set the default - if (!$scope.current_tab) { - $scope.current_tab = $scope.tabs[0]; - $scope.go($scope.current_tab.route, $scope.current_tab.params, $scope.current_tab.options); - } + if($state.current.name) { + $scope.update_tabs(); + + // if none are active, set the default + if (!$scope.current_tab) { + $scope.current_tab = $scope.tabs[0]; + $scope.go($scope.current_tab.route, $scope.current_tab.params, $scope.current_tab.options); + } + } }], templateUrl: function(element, attributes) { return attributes.templateUrl || 'ui-router-tabs-default-template.html';