I use accordion in my angularjs project.
Here is template:
<uib-accordion close-others="oneAtATime">
<uib-accordion-group heading="{{group.title}}" ng-repeat="group in groups"
ng-class-odd="'panel-info'" ng-class-even="'panel-success'">
{{group.content}}
</uib-accordion-group>
<hr />
<button class="btn btn-default btn-sm" ng-click="addItem()">Add Item</button>
</uib-accordion>
Here is controller:
$scope.oneAtATime = true;
$scope.groups = [
{
title: 'Dynamic Group Header - 1',
content: 'Dynamic Group Body - 1'
},
{
title: 'Dynamic Group Header - 2',
content: 'Dynamic Group Body - 1'
},
{
title: 'Dynamic Group Header - 3',
content: 'Dynamic Group Body - 1'
},
{
title: 'Dynamic Group Header - 4',
content: 'Dynamic Group Body - 1'
},
{
title: 'Dynamic Group Header - 5',
content: 'Dynamic Group Body - 2'
}
];
$scope.item = {
title: 'Dynamic Group Header - The new!!!',
content: 'Dynamic Group Body - 20'
}
$scope.addItem = function() {
$scope.groups.push($scope.item);
};
Here is a working Plunker.
On html template I have button Add Item
when the button is clicked new item has been added and displayed in accordion.
When the new item is added to accordion I need it to be automatically expanded (opened). Any idea how can I achieve it? How can I make the the new added item automatically expanded?