So I'm trying to create a basic angular application that parses some CSV input, and fills a table with the parsed data.
You can see a plunker of what I'm trying to achieve here - http://plnkr.co/edit/6QFT4AcV4KpiSG23EdOS
Basically - as you can see - I have a <textarea>
where the user will paste in some CSV, and the table below should then be filled with the data.
<div class=excelArea>
<textarea name=excelData ng-model=excelData></textarea>
</div>
This is the javascript I have so far, but I'm struggling with a few things
1. Seperating the email from the name
2. Pushing the data back into the $scope.inviteList;
app.controller(InviteController, function($scope) {
//Initliase objects
$scope.excelData = ;
$scope.errorMessage = ;
$scope.inviteList = [];
$scope.$watch(excelData, function() {
var lines, lineNumber, data, length;
lines = $scope.excelData.match(/[^rn]+/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
});
};
});
});
Some basic information:
The CSV will be two columns (name, email) and will look like this:
John Thompson,[email protected]
Robin Peters, [email protected]
Bill Bob, [email protected]