Currently, I am working on building a simple angular application that can parse CSV input and populate a table with the extracted data.
If you're curious about what I'm trying to accomplish, feel free to check out this Plunker demo - http://plnkr.co/edit/6QFT4AcV4KpiSG23EdOS
Essentially, my goal is to have a <textarea>
where users can paste CSV data, which will then be used to populate the table below.
<div class="excelArea">
<textarea name="excelData" ng-model="excelData"></textarea>
</div>
Here is the current JavaScript code I have written, but I'm encountering difficulties with:
1. Extracting the email address from the name
2. Updating the $scope.inviteList;
with the parsed data
app.controller("InviteController", function($scope) {
//Initialize objects
$scope.excelData = "";
$scope.errorMessage = "";
$scope.inviteList = [];
$scope.$watch("excelData", function() {
var lines, lineNumber, data, length;
lines = $scope.excelData.match(/[^\r\n]+/g);
lineNumber = 0;
for (var i = lines.length - 1; i >= 0; i--) {
l = lines[i];
lineNumber++;
data = l.split(/\t/);
var email = ? ? ?
var name = ? ? ?
$scope.inviteList.push({
name: name,
email: email,
status: "not sent"
});
};
});
});
Just some basic details:
The CSV format will consist of two columns (name, email) and will be structured like this:
John Thompson,<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e58f8a8d8ba5918d8a8895968a8bcb868a88">[email protected]</a>
Robin Peters, <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abd9c4c9c2c5ebdbcedfced9d885c8c4c6">[email protected]</a>
Bill Bob, <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7113181d1d31131e135f121e1c">[email protected]</a>