Skip to content

Instantly share code, notes, and snippets.

@nethoncho
Created February 15, 2015 12:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nethoncho/5b1a51113783f23011b3 to your computer and use it in GitHub Desktop.
Save nethoncho/5b1a51113783f23011b3 to your computer and use it in GitHub Desktop.
Handling document.visibilitychange in AngularJS
// See http://megatuto.com/formation-JAVASCRIPT.php?JAVASCRIPT-Examples=handling+document.visibilitychange+in+AngularJS+Categorie+javascript+angularjs&article=1773
angular.module('myApp', [])
.run(['$rootScope', '$document', function($rootScope, $document) {
$document[0].addEventListener("visibilitychange", function() {
$rootScope.$broadcast('$visibilitychange', $document[0].hidden);
});
}])
.controller('UserNavCtrl', ['$scope', '$log',
function($scope,$log) {
$scope.$on('$visibilitychange', function(event, data) {
$log.info('visibilitychange');
$log.info(data);
});
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment