角:操纵事件触发顺序 - 即NG-模糊和放大器; NG-点击? [英] Angular: manipulating event firing order - namely ng-blur & ng-click?

查看:189
本文介绍了角:操纵事件触发顺序 - 即NG-模糊和放大器; NG-点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个HTML元素:<艾礼富> <贝丝> 。元素<艾礼富> 有一个 NG-模糊属性和元素<贝丝&GT ; NG-点击属性

如果我在专注于elment <艾礼富> ,然后点击<贝丝> 出现(根据实验)的 NG-模糊将火第一和 NG-点击接下来将闪光。

http://jsfiddle.net/UTn5y/70/


  1. 将始终是行为?

  2. 我可以改变这种行为没有任何努力?


解决方案

  1. 将始终是行为?

是的,模糊事件总是会首先解雇


  1. 我可以改变这种行为没有任何努力?

没有你不能改变的行为。但是,你可以手工管理。您可以使用$超时在NG-模糊回调,并检查是否可以通过NG-点击被操纵的变量。

 函数ngClick(){
    $ scope.clicked = TRUE;
    //你的code休息
}功能ngBlur(){
    $ scope.clicked = FALSE;
    $超时(函数(){//将ngClick功能后,点击执行情况
        如果(scope.clicked $){
            返回;
        }        //你的code休息
    })
}

下面是一个工作版本:
http://jsfiddle.net/zhfew91j/2/

I have two html elements: <aleph> and <beth>. The element <aleph> has a ng-blur attribute and the element <beth> has the ng-click attribute.

If I am in focus on elment <aleph> and click on <beth> it appears (according to experimentation) that the ng-blur will fire first and ng-click will fire next.

http://jsfiddle.net/UTn5y/70/

  1. Will that always be the behavior?
  2. Could I change that behavior without any effort?

解决方案

  1. Will that always be the behavior?

Yes, the blur event will always be fired first

  1. Could I change that behavior without any effort?

No you can not change the behavior. However, you can manage it by hand. You can use $timeout in your ng-blur callback, and check for a variable which can be manipulated by ng-click.

function ngClick () {
    $scope.clicked = true;
    // rest of your code
}

function ngBlur () {
    $scope.clicked = false;
    $timeout(function () { // will be executed after ngClick function in case of click
        if ($scope.clicked) {
            return;
        }

        // rest of your code
    })
}

Here is a working version: http://jsfiddle.net/zhfew91j/2/

这篇关于角:操纵事件触发顺序 - 即NG-模糊和放大器; NG-点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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