diff --git a/src/tabs/tabs.js b/src/tabs/tabs.js index 0a368a2fb6..4f76440442 100644 --- a/src/tabs/tabs.js +++ b/src/tabs/tabs.js @@ -186,7 +186,8 @@ angular.module('ui.bootstrap.tabs', []) var getActive, setActive; if (attrs.active) { getActive = $parse(attrs.active); - setActive = getActive.assign; + setActive = getActive.assign || angular.noop; + 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 === diff --git a/src/tabs/test/tabs.spec.js b/src/tabs/test/tabs.spec.js index 9bdccad374..e91a22568e 100644 --- a/src/tabs/test/tabs.spec.js +++ b/src/tabs/test/tabs.spec.js @@ -473,6 +473,36 @@ describe('tabs', function() { })); }); + describe('active', function() { + var generateElm; + + beforeEach(inject(function($compile, $rootScope) { + scope = $rootScope.$new(); + + generateElm = function(activeAttr) { + elm = $compile([ + '', + ' ', + ' heading', + ' ', + '' + ].join('\n'))(scope); + + scope.$apply(); + + return elm; + }; + })); + + it('should allow a function as an argument', function() { + scope.isActive = jasmine.createSpy(); + + elm = generateElm('isActive()'); + + expect(scope.isActive).toHaveBeenCalled(); + }); + }); + describe('disabled', function() { beforeEach(inject(function($compile, $rootScope) { scope = $rootScope.$new();