-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Victor Pegado
committed
Oct 3, 2013
1 parent
88a4faa
commit 69133c5
Showing
3 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
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
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'); | ||
}) |
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
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" | ||
} | ||
} |
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
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]); | ||
}); | ||
} | ||
} | ||
}]); |