Which element has the focus on handling ng-blur
Which element has the focus on handling ng-blur
I'm trying to figure out how to get the activeelement | element with focus when handling the ng-blur event. I've tried window.document.activeElement but it is always 'body'.
ng-blur
window.document.activeElement
<body>
<div name="element1" ng-blur="$ctrl.onBlur($event)">element1</div>
<div name="element2" ng-blur="$ctrl.onBlur($event)">element2</div>
</body>
public onBlur($event: any): void
var value = $event.target.attributes["name"].value;
// value is the name of the element where the event is triggered
// but how to get the element to where the focus has gone to?
Fixed it using the $timeout service.
$timeout
public onBlur($event: any): void
this.$timeout(() =>
if (this.$window.document.activeElement)
// do things
, 1);
Yep, 1 works just as well. Changed my question.
– Ralf de Kleine
Aug 29 at 12:39
1 Answer
1
Fixed it using the $timeout service.
public onBlur($event: any): void
this.$timeout(() =>
if (this.$window.document.activeElement)
// do things
, 1);
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
100 is too much. try with 0, 1 or 2 You should get the same result
– AdityaParab
Aug 29 at 11:58