Browse Source

Upload: Fixing link function in directive

Erik Sundell 7 years ago
parent
commit
4fa4c27537
1 changed files with 3 additions and 3 deletions
  1. 3 3
      public/app/features/dashboard/upload.ts

+ 3 - 3
public/app/features/dashboard/upload.ts

@@ -1,7 +1,7 @@
 import coreModule from 'app/core/core_module';
 import coreModule from 'app/core/core_module';
 
 
 const template = `
 const template = `
-<input type="file" id="dashupload" name="dashupload" class="hide"/>
+<input type="file" id="dashupload" name="dashupload" class="hide" onchange="angular.element(this).scope().file_selected"/>
 <label class="btn btn-success" for="dashupload">
 <label class="btn btn-success" for="dashupload">
   <i class="fa fa-upload"></i>
   <i class="fa fa-upload"></i>
   Upload .json File
   Upload .json File
@@ -16,7 +16,7 @@ function uploadDashboardDirective(timer, alertSrv, $location) {
     scope: {
     scope: {
       onUpload: '&',
       onUpload: '&',
     },
     },
-    link: scope => {
+    link: (scope, elem) => {
       function file_selected(evt) {
       function file_selected(evt) {
         const files = evt.target.files; // FileList object
         const files = evt.target.files; // FileList object
         const readerOnload = () => {
         const readerOnload = () => {
@@ -52,7 +52,7 @@ function uploadDashboardDirective(timer, alertSrv, $location) {
       // Check for the various File API support.
       // Check for the various File API support.
       if (wnd.File && wnd.FileReader && wnd.FileList && wnd.Blob) {
       if (wnd.File && wnd.FileReader && wnd.FileList && wnd.Blob) {
         // Something
         // Something
-        document.getElementById('dashupload').addEventListener('change', file_selected, false);
+        elem[0].addEventListener('change', file_selected, false);
       } else {
       } else {
         alertSrv.set('Oops', 'Sorry, the HTML5 File APIs are not fully supported in this browser.', 'error');
         alertSrv.set('Oops', 'Sorry, the HTML5 File APIs are not fully supported in this browser.', 'error');
       }
       }