Reputation: 4550
Since adding angular-filter the accordion is not opening on page load. I guess it's something to do with the code is-open="group.isOpen"
and group
not being valid in that instance anymore?, cause the code's now using key, value
? What am I doing wrong?
Here's a plunker of the issue.
** edit: (( And, as requested in the comments, here's a plunker of the accordion opening on page load before adding angular-filter )).
here's the html:
<div ng-controller="AccordionDemoCtrl">
<accordion close-others="oneAtATime">
<accordion-group is-open="group.isOpen" ng-repeat="(key, value) in groups | groupBy: 'title'">
<accordion-heading><i class="glyphicon-plus"></i> {{ key }}
<i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': group.isOpen, 'glyphicon-chevron-right': !group.isOpen}"></i>
</accordion-heading>
<p ng-repeat="group in value"> {{ group.content }}</p>
<ul>
<li ng-repeat="group in value">
{{ group.list }}
</li>
</ul>
</accordion-group>
</accordion>
</div>
Here's the js:
angular.module('app', ['ui.bootstrap','ngSanitize','angular.filter']);
angular.module('app').controller('AccordionDemoCtrl', function ($scope) {
$scope.oneAtATime = true;
$scope.groups = [
{
title: 'title 1',
content: 'content 1',
isOpen: true,
list: 'item0a'
},
{
title: 'title 2',
content: 'Content 2',
list: 'item0b'
},
{
title: 'title 3',
content: 'Content 3',
list: 'item0c'
},
{
title: 'title 4',
content: 'content 4',
list: 'item0d'
},
{
title: 'title 5',
content: 'content 5',
list: 'item0e'
},
{
title: 'title 1',
list: 'item1a'
},
{
title: 'title 1',
list: 'item2a'
},
{
title: 'title 1',
list: 'item3a'
},
{
title: 'title 2',
list: 'item1b'
},
{
title: 'title 2',
list: 'item2b'
},
{
title: 'title 3',
list: 'item1c'
},
{
title: 'title 3',
list: 'item2c'
},
{
title: 'title 4',
list: 'item1d'
},
{
title: 'title 5',
list: 'item1e'
}
];
});
Upvotes: 1
Views: 696
Reputation: 5815
I don't know if you have a specific reason for your object structure, but something like
{
title: 'title 1',
content: 'content 1',
isOpen: true,
list: ['item1a',
'item2a',
'item3a']
}
makes more sense to me. Now you basically don't need to change the actual view much at all, other than adding the list.
<ul>
<li ng-repeat="item in group.list">
{{ item }}
</li>
</ul>
http://plnkr.co/edit/LBNQ2ukERMEzH3gKQ4M6?p=preview
Upvotes: 1