Angularjs手风琴按钮单击面板标题

时间:2014-04-17 14:24:43

标签: angularjs accordion angular-ui-bootstrap

在AngularJS UI Bootstrap中我想在点击 panel-heading 时激活 isopen ,但我找不到办法。 只有在您单击链接时才会激活此版本。

这是我尝试过的;

<accordion-group is-open="isopen">
    <accordion-heading ng-click="isopen=!isopen">
        I can have markup, too! 
        <i class="pull-right glyphicon" 
           ng-class="{'glyphicon-chevron-down': isopen, 'glyphicon-chevron-right': !isopen}"></i>
    </accordion-heading>
    This is just some content to illustrate fancy headings.
</accordion-group>

纳克单击= “ISOPEN =!ISOPEN

This is the link I tried on Plunker

AngularJS UI Bootstrap

提前致谢..

3 个答案:

答案 0 :(得分:59)

修改 更好的解决方案是将ng-click="isopen=!isopen"移至accordion-group元素。通过这种方式打开/关闭面板,单击面板标题上的任何位置,包括边缘。

<accordion close-others="oneAtATime">
    <accordion-group is-open="isopen" ng-click="isopen=!isopen">
        <accordion-heading >
           I can have markup, too! 
           <i class="pull-right glyphicon" 
              ng-class="{'glyphicon-   chevron-down': isopen, 'glyphicon-chevron-right': !isopen}">
           </i>
        </accordion-heading>
        This is just some content to illustrate fancy headings.
    </accordion-group>
</accordion>

结束编辑

<accordion-heading>的内容括在<div>

<accordion close-others="oneAtATime">
    <accordion-group is-open="isopen" >
        <accordion-heading ng-click="isopen=!isopen">
           <div>
            I can have markup, too! 
           <i class="pull-right glyphicon" 
              ng-class="{'glyphicon-   chevron-down': isopen, 'glyphicon-chevron-right': !isopen}">
           </i>
           </div>
       </accordion-heading>
       This is just some content to illustrate fancy headings.
   </accordion-group>
</accordion>

答案 1 :(得分:13)

一个非常简单的基于CSS的解决方案:

    .panel-heading {
        padding: 0;
    }

    .panel-title a {
        display: block;
        padding: 10px 15px;
    }

我不是使用复杂的标题 - 只是如下所示的标题属性,所以我没有用上面的例子测试它。

<uib-accordion-group heading="Details" class="form-horizontal" is-open="true">

答案 2 :(得分:9)

您需要做的是更改accordion-group.html模板,以使标题处理ng-click事件。

<div class="panel {{panelClass || 'panel-default'}}">
  <div class="abc panel-heading" ng-keypress="toggleOpen($event)" ng-click="toggleOpen($event)" >
    <h4 class="panel-title">
      <a href tabindex="0" class="accordion-toggle" accordion-transclude="heading"><span ng-class="{'text-muted': isDisabled}">{{heading}}</span></a>
    </h4>
  </div>
  <div class="panel-collapse collapse" collapse="!isOpen">
      <div class="panel-body" ng-transclude></div>
  </div>
</div>

然后在您的代码中将其指定为accordion-group

的template-url
<accordion-group heading="Dynamic Body Content" template-url="accordion-group.html">

实施例: http://plnkr.co/edit/EXUgyNi8hrqQbh5maJUx?p=preview