Angular: controlling the order in which events are triggered, namely ng-blur & ng-click?

I have two html elements: <aleph>and <beth>. An element <aleph>has an attribute ng-blur, and an element <beth>has an attribute ng-click.

If I focus on elment <aleph>and click on <beth>, it appears (according to the experiment) that it ng-blurlights up first, and ng-clickwill shoot further.

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

  • Will it always be behavior?
  • Can I change this behavior without any effort?
0
source share
1 answer
  • Will it always be behavior?

Yes, the blur event will always be fired first

  • Can I change this behavior without any effort?

, . . $timeout ng-blur , 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
    })
}

: http://jsfiddle.net/zhfew91j/2/

+2

All Articles