我手风琴的标题中有链接。它是这样一种方式,当点击标题上的任何地方时,可以打开手风琴。因此,当点击链接时,不会转到该链接(href
),而是打开手风琴。
所需行为:
我希望在标题中除链接之外的任何位置单击时打开该accodion。 (即,当点击链接时,必须重定向用户并且不得打开手风琴)
<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>
答案 0 :(得分:5)
您需要在ng-click中调用$event.stopPropagation();
- &gt; ng-click="$event.stopPropagation(); fn1();"
答案 1 :(得分:4)
诀窍是在锚点ng-click
处理程序中调用Event.stopPropagation()
:
<a href="https://www.fb.com" ng-click="$event.stopPropagation()">link</a>
这是一个更新的plunker。
答案 2 :(得分:1)
使用
ng-click="$event.stopPropagation()"//this will not apply accordion click event on this link tag
而不是
NG-点击= “FN1()”
答案 3 :(得分:0)
使用accordion-heading
时,其中的所有内容都将转换为<a>
代码。
您的代码将在浏览器中呈现
<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>