Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting window focus the angular way?

Tags:

angularjs

Is there a good angular way to detect window focus? I am using html5 notifications and I would like to only fire if the window is out of focus.

Thanks!

like image 703
fotoflo Avatar asked Jan 05 '15 22:01

fotoflo


1 Answers

There's a built-in angular directive ngFocus here maybe it helps if you attach it to the body

<window, input, select, textarea, a
  ng-focus="">
...
</window, input, select, textarea, a>

Edit: For window focus, there's the $window wrapper and you can do something like:

 $window.onfocus = function(){
   console.log("focused");
 }
like image 80
Cristi Berceanu Avatar answered Sep 30 '22 17:09

Cristi Berceanu