Angularjs accordion ng-click on panel-header

后端 未结 3 1719
有刺的猬
有刺的猬 2021-02-01 04:42

In AngularJS UI Bootstrap I want to activate isopen when panel-heading is clicked, but I couldn\'t find a way. In this version is activated onl

相关标签:
3条回答
  • 2021-02-01 05:19

    What you need to do is change the accordion-group.html template such that it makes the header take the ng-click event.

    <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>
    

    Then in your code specify it as the template-url for the accordion-group

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

    Example: http://plnkr.co/edit/EXUgyNi8hrqQbh5maJUx?p=preview

    0 讨论(0)
  • 2021-02-01 05:20

    A very simple CSS-based solution:

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

    I'm not using complex headings though - just the heading attribute as shown below, so I haven't tested it with the examples above.

    <uib-accordion-group heading="Details" class="form-horizontal" is-open="true">
    
    0 讨论(0)
  • 2021-02-01 05:23

    EDIT: A better solution is to move ng-click="isopen=!isopen" to the accordion-group element. This way the panel is opened/closed clicking anywhere on the panel-heading, including the edges.

    <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>
    

    END EDIT

    enclose the content of <accordion-heading> in a <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>
    
    0 讨论(0)
提交回复
热议问题