[英]Angular UI Bootstrap: Make accordion save state
How can I make the accordion in Angular UI Boot strap save its state? 如何使Angular UI Boot表带中的手风琴保存其状态?
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. 如果有帮助,我正在将SPA与ui-router一起使用,很高兴将状态保存为cookie。
I've not got very far because I haven't figured out how to read the accordion's state, let alone save it. 我还没有走很远,因为我还没有弄清楚如何读取手风琴的状态,更不用说保存它了。
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 {};
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.