1

I have an accordion with links in the header. It is in such a way that the accordion can be opened when clicked anywhere on the header. Because of this when clicked on the link, instead of going to that link (href) the accordion is opened.

Desired behaviour:

I want the accodion to be opened when clicked anywhere in the header except the link. (i.e when clicked on the link, the user must be redirected and accordion must not be opened)

<div>
    <accordion close-others="false">
        <accordion-group is-open="isopen" ng-repeat="ele in arr">
            <accordion-heading>
                <div>
                    <i class="pull-right glyphicon"
                       ng-class="{'glyphicon-chevron-down': isopen, 'glyphicon-chevron-right': !isopen}"></i>
                    <div style="width: 50%; float: left; padding-left: 6cm;">{{ele.a}}
                        <span >
                            <a href="https://www.fb.com">link</a>
                        </span>
                    </div>
                    <div style="text-align: center;">
                        <span>{{ele.b}}</span>
                    </div>
                </div>
            </accordion-heading>
       </accordion-group>
     </accordion>
  </div>

Plnkr

Thiyagu
  • 17,362
  • 5
  • 42
  • 79

4 Answers4

5

You need to call $event.stopPropagation(); in your ng-click -> ng-click="$event.stopPropagation(); fn1();"

PrinceG
  • 982
  • 6
  • 17
4

The trick is to call Event.stopPropagation() inside ng-click handler of anchor:

<a href="https://www.fb.com" ng-click="$event.stopPropagation()">link</a>

Here's an updated plunker.

miensol
  • 39,733
  • 7
  • 116
  • 112
1

use

ng-click="$event.stopPropagation()"//this will not apply accordion click event on this link tag

instead of ng-click="fn1()"

This Might not work on plunk try it in your code.

Minato
  • 4,383
  • 1
  • 22
  • 28
0

When using accordion-heading, everything in it will be turned into an <a> tag.

Your code will be rendered in brower

<h4 class="panel-title">
      <a class="accordion-toggle ng-binding" ng-click="isOpen = !isOpen" accordion-transclude="heading">
                <div class="ng-scope">
                    <i class="pull-right glyphicon glyphicon-chevron-right" ng-class="{'glyphicon-chevron-down': isopen, 'glyphicon-chevron-right': !isopen}"></i>
                    <div style="width: 50%; float: left; padding-left: 6cm;" class="ng-binding">1
                        <span>
                            <a href="https://www.fb.com">link</a>
                        </span>
                    </div>
                    <div style="text-align: center;">
                        <span class="ng-binding">2</span>
                    </div>
                </div>
            </a>
    </h4>

This is solution https://stackoverflow.com/a/14202514/3901308

Community
  • 1
  • 1
hunguyenv
  • 51
  • 1
  • 2