试图从nodejs api调用中获取值,但我得到了像[对象对象]那么如何从数组对象中获取值?
product.component.ts:
this.sendDatatoInsertDb(this.selectedProduct.replace(/\s/g,''),JSON.stringify(this.registerForm.value));
sendDatatoInsertDb(collection,collectionData) {
this.adminService.insertDataintoDb(collection,collectionData).subscribe(
res => { },
err => { console.log(err); }
);
}
this.registerForm.value 就像
{
"p_id": "C5",
"product_name": "name",
"product_weight": "250gm"
}
admin.service.ts:
insertDataintoDb(collection,insertData){
return this.http.get(environment.apiBaseUrl + '/insertData?collection='+collection+'&collectionData='+insertData);
}
产品.控制器.js:
module.exports.insertData = (req, res, next) => {
let collectionName = req.query.collection;
let collectionData = req.query.collectionData;
console.log(collectionData); //Getting [object Object]
console.log(collectionData.p_id); //Getting undefined
console.log(collectionData.product_name); //Getting undefined
console.log(collectionData.product_weight); //Getting undefined
}
开满天机
相关分类