将csv文件内容从angular js传递到node js,并在node js中解析以插入mongo db
Pass csv file content from angular js to node js and parse in node js to insert in mongo db
我有这个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。
试试下面的代码,注意我们使用的是这个>$scope,Angular文档建议这样做。
我过去一直在使用json文件,所以我不一定知道这是否适用于csv文件。
MyApp.query();
angular.
module('myApp').
controller: ['MyApp',
function MyAppController(MyApp) {
this.myApp = MyApp.query();
}
]
});
从csv/json文件检索数据后,应该在li中使用ngRepeat来显示要在html正文部分中显示的数据
<li ng-repeat="data in $ctrl.myApp"
<p>{{myApp.data}}</p>
</li>
我希望这能有所帮助,祝你好运。
相关文章:
- 在索引.html和应用.js [node.js] 之间共享变量
- JS(node.js)而循环不起作用
- 如何使用 JS (Node.js) 防止 HTTP 查询中允许使用 UTF8 字符串
- Angular JS & Node Webkit Routing
- 当作为脚本运行时.js Node中“this”的上下文是什么
- JS/Node:- 使用 node.io 选择标记
- JavaScript 如何让节点在返回 node.js/Node-RED 之前等待
- 处理快速连续的函数调用 - Javascript / underscore.js / node.js
- 如何在一台服务器中运行不同的.js文件.js NODE JS中的文件
- JS node-mysql bools 表现得很奇怪
- Node.js+Node Webkit+基于Node串行端口的应用程序-这可能吗
- 如何在Express.js/Node.js中检查查询字符串是否有值
- Express.Js, Node.Js, MongoDB Questions
- 在JS/Node中,当多个人编辑相同的记录时,如何避免数据冲突?有图案吗
- 服务器端js(node.js)上的同步
- 将参数从jade发送到js/node
- angular.js+node.js/electron中的Promise;不起作用
- 是否有可能确定我的应用程序的aws实例使用js/node aws-sdk
- Image Magick模块抛出奇怪的错误(Express js Node js)
- 用JS (Node.js)读取文本文件'