27

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

3 Answers 3

60

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>
Sign up to request clarification or add additional context in comments.

12 Comments

But this way it is closed, if you click on panel-body
The isopen is not necessary here, the solution with the enclosing div is perfect without the custom isopen variable.
There's a problem with this approach, it only makes the text area clickable but not the whole control so if you click near the edges it won't work. You can see from here plnkr.co/edit/0aiIabxogB1oKIhbjHXa
@ArchimedesTrajano move the ng-click attribute to the accordion-group element. see this plunkr plnkr.co/edit/IshCNSF6jjWBt9BCukTz?p=preview
you need to change the plnkr slightly so there's no space in the glypicons-chevron-down
|
14

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

2 Comments

That's exactly what I needed, and very simple. Thanks! (and I'm using <uib-accordion-heading>, though a basic one)
@Sean can you please help me to solve this issue stackoverflow.com/questions/50073157/…
10

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

2 Comments

This is the right thing to do. It works like a charm !
@AlexandreD. can you please help me to solve this issue stackoverflow.com/questions/50073157/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.