有没有办法强制纳克单击第一个执行的父母,然后在孩子 [英] is there a way to force ng-click to execute first on parent, then on child

查看:119
本文介绍了有没有办法强制纳克单击第一个执行的父母,然后在孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个后续问题<一href=\"http://stackoverflow.com/questions/33026912/which-ng-click-takes-$p$pcedence-in-a-table?noredirect=1#comment53876193_33026912\">which NG-点击花费precedence在一个表中?

基本上,我想确保,只要单击该单元格,动作1将首先执行,完成,其次是动作2。有没有办法强制执行呢?

 &LT;表&gt;
 &LT;&TBODY GT;
  &LT; TR NG重复=...NG点击=ctrl.action1()&GT;
    &所述; TD&GT;
      &所述;类别=...纳克点击=ctrl.action2()&GT;&下; I类=...&GT;&下; / I GT;&下; / A&GT;
    &LT; / TD&GT;
  &LT; / TR&GT;
 &LT; / TBODY&GT;
&LT; /表&gt;


解决方案

这是我可以想,不要让事件冒泡并调用动作1 最好在动作2

 &LT;一类=...NG点击=ctrl.action2($事件)&GT;&LT; I类=...&GT;&LT / I&GT;&下; / A&GT;

控制器

  $ scope.action2 =功能(EVT){
     evt.stopPropagation();
     $ scope.action1();
     //其他动作2 code
}

动作1不承担任何异步操作()键,你可能需要在其他参数传递的数据项目在该行

还有一个另外还向HTML摆脱动作2 的,事件传递到行动之一,并检查事件的目标。

This is a follow-up question to which ng-click takes precedence in a table?

Basically, I'd like to ensure, that whenever the cell is clicked, action1 will be executed first, completed, followed by action2. Is there a way to enforce that?

<table>
 <tbody>
  <tr ng-repeat="..."  ng-click="ctrl.action1()" >
    <td>
      <a class="..." ng-click="ctrl.action2()"><i class="..."></i></a>
    </td>
  </tr>
 </tbody>
</table>

解决方案

This is the best I can think of, don't let the event bubble and call action1 from inside action2

<a class="..." ng-click="ctrl.action2($event)"><i class="..."></i></a>

Controller

$scope.action2 = function(evt){
     evt.stopPropagation();
     $scope.action1();
     // other action2 code
}

Assumes no asynchronous operations in action1() and you probably need to pass in other arguments for data item on that row

There is an alternative also to get rid of action2 in html, pass the event into action one and check the target of event

这篇关于有没有办法强制纳克单击第一个执行的父母,然后在孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆