Last active
October 14, 2016 00:35
-
-
Save ashishtilara/f6952a353d691ed6f4e1c7403ea88a9b to your computer and use it in GitHub Desktop.
angular-csv-upload html5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ctrl, | |
module; | |
module = ng.module("SYS.Directive.FileReader", [ | |
"ng" | |
]); | |
ctrl = function ($parse) { | |
return { | |
restrict: "A", | |
scope: false, | |
link: function (scope, element, attrs) { | |
var fn = $parse(attrs.fileReader); | |
element.on("change", function (onChangeEvent) { | |
var reader = new FileReader(); | |
reader.onload = function (onLoadEvent) { | |
scope.$apply(function () { | |
fn(scope, {$fileContent: onLoadEvent.target.result}); | |
}); | |
}; | |
reader.readAsText((onChangeEvent.srcElement || onChangeEvent.target).files[0]); | |
}); | |
} | |
}; | |
}; | |
ctrl.prototype.constructor = ctrl; | |
module.directive("fileReader", ctrl); | |
ctrl.$inject = ["$parse"]; | |
return module; | |
//HTML | |
//<input type="file" title="Choose File" file-reader="ctrl.showContent($fileContent)" accept=".csv" /> | |
/* | |
//Controller Function | |
ctrl.prototype.showContent = function ($fileContent) { | |
this.content = $fileContent; | |
}; | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment