【发布时间】:2016-08-08 09:53:18
【问题描述】:
我有这个 ReadCSV.js,我在其中从 Angular js 检索 csv 文件内容
app.get('/index.html', function(req, res) {
res.sendFile(__dirname + '/index.html');
});
app.post('/add_event', function(req, res, next) {
console.log("Node JS File1 :" +req);
var finalData = req.body.test;//value is undefined
console.log("Node JS File : " + finalData);//value is undefined
index.html
var myapp = angular.module('myapp', []);
myapp.controller('MainCtrl', function ($scope,$http) {
$scope.showContent = function($fileContent){
$scope.content = $fileContent;
var test= $fileContent;
alert(test);
};
$scope.submit = function(test){
//
$http.post('/add_event', $fileContent)
.success(function(){
console.log( "here" +$fileContent);
});
}
<body ng-controller="MainCtrl">
<form ng-submit="submit()">
<div class="test">
<div class="panel-heading">
<h3 class="panel-header">Upload Events</h3>
</div>
<input class="btn btn-primary" type="file" on-read-
file="showContent($fileContent)"/></br>
<button class="btn btn-primary btn-block" ng-click="processData(content)"
type="submit">
Upload File
</button>
</div>
</form>
<div class="test2">
{{content}}
</div>
我得到未定义的价值。 如何将 csv 内容从 angular js 传递到 node js 并解析它,以便我可以插入 mongodb。
【问题讨论】:
标签: javascript angularjs node.js mongodb csv