I need to detect the file input dialog once i try to close without any change, but i can't do in angular , i found the solution for the problem but using javascript only and i tried to convert to angular code but its not working properly.
I tried to convert the js code to angular.
@ViewChild('file') file: ElementRef;
constructor(@Inject(DOCUMENT) private document: any) {}
I use the document object of js like the above.
After file input is clicked it execute the onClick function below.
onClick() {
console.log('On Click');
this.document.body.onfocus = this.test();
}
test() {
console.log(this.selectedFile);
if (this.selectedFile != null) {
if (this.selectedFile.length) {
alert('ROAR! FILES!');
} else {
alert('*empty wheeze*');
}
}
this.document.body.onfocus = null;
}
you can get the javascript version of code from here `
http://jsfiddle.net/Shiboe/yuK3r/6/`
http://jsfiddle.net/Shiboe/yuK3r/6/
I need this code works for Angular 4, help me out.