Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs accordion ng-click on panel-header

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 only if you click the link.

Here's what I tried;

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

ng-click="isopen=!isopen"

This is the link I tried on Plunker

AngularJS UI Bootstrap

Thanks in advance..

like image 468
Alpan Karaca Avatar asked Apr 17 '14 14:04

Alpan Karaca


3 Answers

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>
like image 185
klode Avatar answered Sep 30 '22 13:09

klode


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">
like image 36
Sean Avatar answered Sep 30 '22 13:09

Sean


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

like image 41
Archimedes Trajano Avatar answered Sep 30 '22 13:09

Archimedes Trajano