Reputation: 2320
How can I make the accordion in Angular UI Boot strap save its state?
The behaviour I'd like is what a user clicks on a link inside the accordion, then later clicks back, the same groups are expanded as before.
If it helps, I'm using an SPA with ui-router, and I'm happy to save the state it a cookie.
I've not got very far because I haven't figured out how to read the accordion's state, let alone save it.
Upvotes: 2
Views: 569
Reputation: 9742
Just like this:
<accordion>
<accordion-group heading="Scrooge Mcduck" is-open="storage.mcduck" ng-click="select('mcduck')">
Quack Wealthy!
</accordion-group>
<accordion-group heading="LaunchPad Mcduck" is-open="storage.launchpad" ng-click="select('launchpad')">
Quack Pilot!
</accordion-group>
</accordion>
angular.module('myApp').controller('AccordionController', function ($scope, DuckStorage) {
$scope.storage = DuckStorage;
$scope.select = function(duck) {
DuckStorage[duck] = !DuckStorage[duck];
}
});
angular.module('MyApp').factory('DuckStorage', function () {
return {};
});
Upvotes: 1