I'm trying to load a local csv file (or json file) in an angular2 project. I've tried a few variations per other SO questions (e.g., this) or github issues, including:
1.) Setting up a local server using python -m SimpleHTTPServer
(which serves to port 8000), and executing:
d3.csv("http://127.0.0.1:8000/master_grades_lecture.csv", function(error, data){
console.log(data[0]);
});
When I do this, I can't just navigate to localhost:8000 in my browser and see the webapp working on index.html, because I've been using the Angular cli to set up my project, and it seems that it can only render when I run ng serve
(which runs on port 4200).
2.) When I try to load this using ng serve
on port 4200, and I change the above code to,
d3.csv("master_grades_lecture.csv", function(error, data){
console.log(data[0]);
});
I get an Access-Control-Allow-Origin related error.
Finally, there are also some typing issues when I compile that don't seem to yield many helpful insights when I search for them:
ERROR in src/app/grade-display/grade-display.component.ts(20,41): error TS2345: Argument of type '(error: DSVRowString, data: number) => void' is not assignable to parameter of type '(rawRow: DSVRowString, index: number, columns: string[]) => DSVRowAny'. Type 'void' is not assignable to type 'DSVRowAny'.
These may or may not be separate issues. I'll be happy to provide a reproducible example if people feel like it's needed, but my hope is that somebody has had to deal with this issue before and knows exactly what's going on here. Forgive the newness to this topic.
UPDATE a reproducible example can be found here:
git clone https://github.com/Atticus29/whatismygrade.git
cd whatismygrade
git checkout SO
//create a test csv file in the app directory called master_grades_lecture.csv
rm package-lock.json
npm install
ng serve
Navigate to localhost:4200/test in browser