如何在不单击div的情况下单击可点击div(ng-click)内的标签?

时间:2016-12-28 18:25:14

标签: javascript html css angularjs

以下是代码:

<div ng-click="grid.appScope.navToPage(row)"class="ui-grid-cell" ui-grid-cell style="cursor: pointer">
   <div class="ui-grid-cell-contents">
     <a ng-href="/mywebpage/2" target="_blank">
       <span class="glyphicon glyphicon-new-window"></span>
     </a>
   </div>'
</div>

我想找出一些方法可以点击标记链接,而无需点击ng-click的div。有没有办法做到这一点?

2 个答案:

答案 0 :(得分:6)

您可以使用许多角度指令(例如$event.stopPropagation())上提供的ng-click来阻止点击传播。请查看此问题AngularJS ng-click stopPropagation

在您的情况下,锚标记应如下所示:

<a ng-href="/mywebpage/2" ng-click="$event.stopPropagation()" target="_blank">
   <span class="glyphicon glyphicon-new-window"></span>
</a>     

答案 1 :(得分:2)

试试这个

<a ng-href="/mywebpage/2" target="_blank" ng-click="$event.stopPropagation()"><span class="glyphicon glyphicon-new-window"></span></a>