diff --git a/src/accordion/accordion.js b/src/accordion/accordion.js index 9541aea01b..e18e2d04d7 100644 --- a/src/accordion/accordion.js +++ b/src/accordion/accordion.js @@ -5,10 +5,13 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse']) }) .controller('AccordionController', ['$scope', '$attrs', 'accordionConfig', function ($scope, $attrs, accordionConfig) { - + // This array keeps track of the accordion groups this.groups = []; + // Keep reference to user's scope to properly assign `is-open` + this.scope = $scope; + // Ensure that all the groups in this accordion are closed, unless close-others explicitly says not to this.closeOthers = function(openGroup) { var closeOthers = angular.isDefined($attrs.closeOthers) ? $scope.$eval($attrs.closeOthers) : accordionConfig.closeOthers; @@ -78,12 +81,9 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse']) getIsOpen = $parse(attrs.isOpen); setIsOpen = getIsOpen.assign; - scope.$watch( - function watchIsOpen() { return getIsOpen(scope.$parent); }, - function updateOpen(value) { scope.isOpen = value; } - ); - - scope.isOpen = getIsOpen ? getIsOpen(scope.$parent) : false; + accordionCtrl.scope.$watch(getIsOpen, function(value) { + scope.isOpen = !!value; + }); } scope.$watch('isOpen', function(value) { @@ -91,7 +91,7 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse']) accordionCtrl.closeOthers(scope); } if ( setIsOpen ) { - setIsOpen(scope.$parent, value); + setIsOpen(accordionCtrl.scope, value); } }); } diff --git a/src/accordion/docs/demo.html b/src/accordion/docs/demo.html index f8627f51ef..f75f5cf95e 100644 --- a/src/accordion/docs/demo.html +++ b/src/accordion/docs/demo.html @@ -5,7 +5,7 @@ - + This content is straight in the template. @@ -16,9 +16,9 @@
{{item}}
- + - I can have markup, too! + I can have markup, too! This is just some content to illustrate fancy headings. diff --git a/src/accordion/test/accordionSpec.js b/src/accordion/test/accordionSpec.js index cbafd566d8..143ca73270 100644 --- a/src/accordion/test/accordionSpec.js +++ b/src/accordion/test/accordionSpec.js @@ -232,7 +232,17 @@ describe('accordion', function () { it('should open the group with isOpen set to true', function () { expect(findGroupBody(0).scope().isOpen).toBe(false); expect(findGroupBody(1).scope().isOpen).toBe(true); - }); + }); + + it('should toggle variable on element click', function() { + findGroupLink(0).click(); + scope.$digest(); + expect(scope.open1).toBe(true); + + findGroupLink(0).click(); + scope.$digest(); + expect(scope.open1).toBe(false); + }); }); describe('is-open attribute with dynamic content', function() {