我想通过单击按钮从内部关闭手风琴。我试图将isOpen设置为false,但是它不起作用。有什么办法可以在单击按钮时将其关闭吗?谢谢。

在这里柱塞:https://plnkr.co/edit/3xMnWRPOoEHPmguaQxd0?p=preview



<div uib-accordion-group is-open="isOpen" class="panel-default" heading="{{group.title}}" ng-repeat="group in groups">
  {{group.content}}
  <button ng-click="close()">close this</button>
</div>




$scope.groups = [
    {
      title: 'Dynamic Group Header - 1',
      content: 'Dynamic Group Body - 1'
    },
    {
      title: 'Dynamic Group Header - 2',
      content: 'Dynamic Group Body - 2'
    }
  ];


  $scope.isOpen = false;

  $scope.close = function(){
    $scope.isOpen = false;
  }

最佳答案

我将isOpen放入集合中,以使每个手风琴药丸具有单独的切换(使每个药丸分别切换),并且可以正常工作,请检查以下代码:

控制器:

$scope.groups = [
{
  title: 'Dynamic Group Header - 1',
  content: 'Dynamic Group Body - 1',
  isOpen: false
},
{
  title: 'Dynamic Group Header - 2',
  content: 'Dynamic Group Body - 2',
  isOpen: false
}
];

$scope.items = ['Item 1', 'Item 2', 'Item 3'];

$scope.addItem = function() {
  var newItemNo = $scope.items.length + 1;
  $scope.items.push('Item ' + newItemNo);
};

$scope.close = function(group){
  group.isOpen = false;
};


视图:



<div uib-accordion-group is-open="group.isOpen" class="panel-default" heading="{{group.title}}" ng-repeat="group in groups">
  {{group.content}}
  <button ng-click="close(group)">close this</button>
</div>




我已经修改了您的矮人:
https://plnkr.co/edit/pBT0fbNJtQhgc5kZlLbO?p=preview

08-25 10:36
查看更多