javascript - Pass csv file content from angular js to node js and parse in node js to insert in mongo db -
i have readcsv.js retrieving csv file contents angular js
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 undefined console.log("node js file : " + finaldata);//value 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>
i getting value undefined. how pass csv content angular js node js , parse can insert in mongodb.
try below code, note using > $scope, angular documentation suggests doing so.
i've been using json files in past, don't know if work csv file.
myapp.query(); angular. module('myapp'). controller: ['myapp', function myappcontroller(myapp) { this.myapp = myapp.query(); } ] });
after retrieve data csv/json file, should use ngrepeat in li display data want display in html body section
<li ng-repeat="data in $ctrl.myapp" <p>{{myapp.data}}</p> </li>
i hope helps somehow, best of luck it.
Comments
Post a Comment