Skip to content

Commit

Permalink
add directive
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Pegado committed Oct 3, 2013
1 parent 88a4faa commit 69133c5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
angular-fileparse-directive
angular-file-directive
===========================

Angularjs directive for parsing files
File parsing directive for Angular.js

1. `bower install angular-file-directive`
2. Include the `file.js` script into your app.
3. Add `file` as a module dependency to your app.

4. Insert code in to view

<input type="file" file="csvFile" accept="text/csv">

5. Insert code in controller

$scope.csvFile = '';
$scope.items = [];
$scope.$watch('csvFile', function () {
$scope.items = $scope.csvFile.split('\n');
})
20 changes: 20 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "angular-file-directive",
"version": "0.0.1",
"homepage": "https://github.com/vpegado/angular-file-directive",
"authors": [
"Victor Pegado <[email protected]>"
],
"description": "Angular directive for parsing files",
"main": "file.js",
"keywords": [
"angular",
"file",
"directive",
"filereader"
],
"license": "MIT",
"dependencies": {
"angular": "~1.0.5"
}
}
19 changes: 19 additions & 0 deletions file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
angular.module('file', [])
.directive("file", [function () {
return {
scope: {
file: "="
},
link: function (scope, element, attributes) {
element.bind("change", function (changeEvent) {
var reader = new FileReader();
reader.onload = function (loadEvent) {
scope.$apply(function () {
scope.file = loadEvent.target.result;
});
}
reader.readAsText(changeEvent.target.files[0]);
});
}
}
}]);

0 comments on commit 69133c5

Please sign in to comment.