I'm playing around with the angular group-by filter- I've tried to replicate their example, it's not working yet. What am I doing wrong?
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>
{{group.content}}
<ul>
<li ng-repeat="group in value">
list item: {{group.list}}
</li>
</ul>
</accordion-group>
</accordion>
</div>
Here's the js:
angular.module('app', ['ui.bootstrap','ngSanitize','angular.filter']);
angular.module('ui.bootstrap.demo').controller('AccordionDemoCtrl', function ($scope) {
$scope.oneAtATime = true;
$scope.groups = [
{
title: 'title 1',
content: 'content 1',
isOpen: true
},
{
title: 'title 2',
content: 'Content 2'
},
{
title: 'title 3',
content: 'Content 3'
},
{
title: 'title 4',
content: 'content 4'
},
{
title: 'title 5',
content: 'content 5'
},
{
title: 'title 1',
list: 'item1'
},
{
title: 'title 1',
list: 'item2'
},
{
title: 'title 1',
list: 'item3'
},
{
title: 'title 2',
list: 'item1'
},
{
title: 'title 2',
list: 'item2'
},
{
title: 'title 3',
list: 'item1'
},
{
title: 'title 3',
list: 'item2'
},
{
title: 'title 4',
list: 'item1'
},
{
title: 'title 5',
list: 'item1'
}
];
});
Maybe I'm approaching this wrong, perhaps my groups in the js file is funky, what I'm trying to do is basically have a collection that has one title and one content entry for each collection, but multiple list entries (basically multiple bullet points). But it seems from their example what I am doing should work?
What I'd prefer to do in the js file is something like this:
$scope.groups = [
{
title: 'title 1',
content: 'content 1',
item: 'bullet point 1',
isOpen: true
},
{
title: 'title 2',
content: 'Content 2'
item: 'bullet point 1',
item: 'bullet point 2'
},
{
title: 'title 3',
content: 'Content 3',
item: 'bullet point 1',
item: 'bullet point 2',
item: 'bullet point 3'
},
{
title: 'title 4',
content: 'content 4',
item: 'bullet point 1'
},
{
title: 'title 5',
content: 'content 5',
item: 'bullet point 1',
item: 'bullet point 2'
}
];