Apply delay on ng-blur
I am using ng-focus
and ng-blur
to show / hide a button. on focus
input, the button is displayed, and on blur
it is hidden. Show / hide is done with ng-show
. When this button is pressed, the function is called.
The problem is that ng-blur
we are called first and the button is hidden before the click event is triggered, so the function that should be called from that button will never be called.
I have already fixed it using setTimeout()
, but later found it was not a very good solution. Is there any other way to fix this problem?
source to share
I think using bool can help you define the state if it needs to hide or show the button. By hovering over the bool button, you can determine whether the blur function is performed.
Try the following methods:
HTML:
<div ng-app ng-controller="LoginController">
<div>{{ text }}</div>
<input ng-focus="focus()" ng-blur="blur()"></input>
<button ng-click="click()" ng-show="show==true" ng-mouseover="mouseover()">Click to change</button>
</div>
angularjs:
function LoginController($scope) {
$scope.show=false;
$scope.blurAll = true;
$scope.text = "this thing will change on click";
$scope.focus = function(){
console.log("buu");
$scope.show=true;
}
$scope.blur = function(){
if(blurAll){
console.log("baaa");
$scope.show=false;
}
}
$scope.click = function(){
alert("fuu");
$scope.text = "We changed it";
$scope.show = false;
}
$scope.mouseover = function(){
blurAll = false;
};
}
source to share