Commit 4fa4c275 by Erik Sundell Committed by Daniel Lee

Upload: Fixing link function in directive

parent ef3beb1f
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) { ...@@ -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) { ...@@ -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');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment