I am posting form-data.
Front-end is in angular Js.
Iam able to post data from front-end,because i logged on angular console, and it's showing all data.
But when did console.log on node js server, then I am getting array fields as [object object]
Non-array fields i.e Objects are coming correct.
Model :
var productsSchema = new Schema({
productName: {type: String, required: false},
productDescription: {type: String, required: false},
productStock: [
{
size: {type: Number, required: false},
price: {type: Number, required: false},
imagePaths: [{
image1:{type: String, required: false},
image2:{type: String, required: false},
image3:{type: String, required: false},
image4:{type: String, required: false}
}]
}
])}
Angular Code
$scope.product = {};
$scope.newProduct = function(){
var formData = new FormData;
for(key in $scope.product){
formData.append(key, $scope.product[key]);
}
//getting the files
var file = $('#file')[0].files[0];
formData.append('image', file);
//formData.append('product',$scope.product);
//Post data
$http.post('http://localhost:3000/products/api/new-product',formData,{
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
}).then(function(res){
$scope.item = res.data;
});
console.log($scope.product);
//console.log(file.name);
}
Why this happening, what I am doing wrong?
Please help.
答案 0 :(得分:0)
In NodeJS, console.log and console.dir would only go 2 levels deep when displaying your object (you see [Object] instead of actual contents of nested objects). If you wanna see full object either you can stringify or use util.inspect function