Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 0702403

Browse files
bekospkozlowski-opensource
authored andcommitted
refactor(accordion): use optional binding for isOpen
Closes #1596
1 parent a1edfe9 commit 0702403

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

src/accordion/accordion.js

+6-19
Original file line numberDiff line numberDiff line change
@@ -54,46 +54,33 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
5454
})
5555

5656
// The accordion-group directive indicates a block of html that will expand and collapse in an accordion
57-
.directive('accordionGroup', ['$parse', function($parse) {
57+
.directive('accordionGroup', function() {
5858
return {
5959
require:'^accordion', // We need this directive to be inside an accordion
6060
restrict:'EA',
6161
transclude:true, // It transcludes the contents of the directive into the template
6262
replace: true, // The element containing the directive will be replaced with the template
6363
templateUrl:'template/accordion/accordion-group.html',
64-
scope:{ heading:'@' }, // Create an isolated scope and interpolate the heading attribute onto this scope
64+
scope: {
65+
heading: '@', // Interpolate the heading attribute onto this scope
66+
isOpen: '=?'
67+
},
6568
controller: function() {
6669
this.setHeading = function(element) {
6770
this.heading = element;
6871
};
6972
},
7073
link: function(scope, element, attrs, accordionCtrl) {
71-
var getIsOpen, setIsOpen;
72-
7374
accordionCtrl.addGroup(scope);
7475

75-
scope.isOpen = false;
76-
77-
if ( attrs.isOpen ) {
78-
getIsOpen = $parse(attrs.isOpen);
79-
setIsOpen = getIsOpen.assign;
80-
81-
scope.$parent.$watch(getIsOpen, function(value) {
82-
scope.isOpen = !!value;
83-
});
84-
}
85-
8676
scope.$watch('isOpen', function(value) {
8777
if ( value ) {
8878
accordionCtrl.closeOthers(scope);
8979
}
90-
if ( setIsOpen ) {
91-
setIsOpen(scope.$parent, value);
92-
}
9380
});
9481
}
9582
};
96-
}])
83+
})
9784

9885
// Use accordion-heading below an accordion-group to provide a heading containing HTML
9986
// <accordion-group>

src/accordion/docs/demo.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
Open only one at a time
55
</label>
66

7-
<accordion close-others="oneAtATime">
8-
<accordion-group heading="Static Header, initially expanded" is-open="true">
7+
<accordion close-others="oneAtATime" ng-init="isFirstOpen = true">
8+
<accordion-group heading="Static Header, initially expanded" is-open="isFirstOpen">
99
This content is straight in the template.
1010
</accordion-group>
1111
<accordion-group heading="{{group.title}}" ng-repeat="group in groups">

0 commit comments

Comments
 (0)