I am trying to capture the event when the user close or cancel the File Upload
Window
<input type="file">
Since there's no built in listener for the close event of the file upload, I am trying to capture it via the document.body.focus
event, something like the one suggested here
I'm getting it to run using javascript
document.body.onfocus = function() { console.log("hit me") }
Now I need to implement it in Angular in my directive so that I could put logic inside the focus
event using the objects in the controller.
How to access the onfocus
event of document.body
inside an angular controller?
From @Phil suggestion (using link)
... this is a directive with controller
angular.directive("addPost", addPost);
addPost.$inject = ["$document", "$log"];
function addPost($document, $log) {
return {
...
link: link,
...
};
function link() {
$document.find('body').on('focus', function (e) {
$log.debug('HIT ME!');
});
}