diff --git a/src/tabs/tabs.js b/src/tabs/tabs.js index 79ba1db..68da560 100644 --- a/src/tabs/tabs.js +++ b/src/tabs/tabs.js @@ -12,7 +12,7 @@ angular.module('mm.foundation.tabs', []) .controller('TabsetController', ['$scope', function TabsetCtrl($scope) { var ctrl = this, tabs = ctrl.tabs = $scope.tabs = []; - + ctrl.select = function(tab) { angular.forEach(tabs, function(tab) { tab.active = false; @@ -183,30 +183,20 @@ angular.module('mm.foundation.tabs', []) }, compile: function(elm, attrs, transclude) { return function postLink(scope, elm, attrs, tabsetCtrl) { - var getActive, setActive; + //if we've provided an active in attrs + //we're initializing which tab is selected + //once we use it once to initialize scope.active we don't + //want to watch it anymore or use it in overriding the selection + //behavior of end-users. + var getActive; + if (attrs.active) { getActive = $parse(attrs.active); - setActive = getActive.assign; - scope.$parent.$watch(getActive, function updateActive(value, oldVal) { - // Avoid re-initializing scope.active as it is already initialized - // below. (watcher is called async during init with value === - // oldVal) - if (value !== oldVal) { - scope.active = !!value; - } - }); scope.active = getActive(scope.$parent); - } else { - setActive = getActive = angular.noop; } scope.$watch('active', function(active) { - if( !angular.isFunction(setActive) ){ - return; - } - // Note this watcher also initializes and assigns scope.active to the - // attrs.active expression. - setActive(scope.$parent, active); + if (active) { tabsetCtrl.select(scope); scope.onSelect();