EDIT:
Node/Express Code inserting into sqlite database:
var db = new sqlite3.Database('db/gnarboxmm.db');
router.post('/api/jobs', function(req,res){
tsql = "INSERT INTO Jobs ('Job_File_Name', 'Job_Transporter_ID') VALUES ('"+req.body.File_Name+"','"+req.body.Trans_ID+"')";
console.log(tsql);
db.run(tsql, function(err,rows){
res.end("success");
});
});
UPDATE: I changed my code and am closer now. By adding the $http request inside forEach loop, I'm getting much closer to what I need. New code is here:
angular.forEach($rootScope.moveArray, function(value){
$http.post('/api/jobs', {'File_Name':value,
'Trans_ID':'Backup'});
}, $rootScope.jobData);
Still not quite there. The request object on the server side now shows two valid entries (where File_Name and Trans_ID are defined), but has a third "undefined" entry.
I am attempting to collect a series of file names the user interacting with my view then implement the file names into objects to be sent to the server in $http.post.
So far, I've successfully created an array and parsed out array items into an array of objects that's ready to go. Here's the chunk of code I used to create the object from my array called "$rootScope.moveArray"
$scope.sendBackup = function(){
angular.forEach($rootScope.moveArray, function(value){
this.push({'File_Name':value,
'Trans_ID':'Backup'});
}, $rootScope.jobData);
console.log($rootScope.jobData);
The console.log returns "[object, object]" and when I drill down I get two objects with properly assigned File_Name's and Trans_ID's.
This is where I run into trouble. I'm using an $http.post:
$http.post('/api/jobs', $rootScope.jobData);
Checking in on the server side. I'm using express & bodyparser to handle API routing and req/res objects. With the code how it is above, when I log the properties "File_Name" and "Trans_ID" of the req object, I get undefined. I have done a bit of experimentation. If I give $rootScope.jobData an index value ($rootScope.jobData[0]), the $http.post works on the first object in the array. The request object looks like it should with File_Name:'/validPath' and Trans_ID:'Backup'
My intuition is that I'll need to use another forEach loop for $rootScope.jobData to get $http.post working properly. I haven't been successful in this pursuit thus far. Does anyone know the solution to this issue? I doubt that angular has NO mechanism for posting arrays of objects and think it's the fact that I'm new to it.