0
我試圖將當前日期作爲對象屬性,並將其轉換爲Json作爲節點後端。我也不知道,如果在節點中的日期屬性將捕獲例如從前端如何在角度對象中使用日期管道並將其格式設置爲節點的JSON?
在角2/4我有
const newCustomer = {
firstName: this.firstName;
lastName: this.lastName;
date: number = Date.now();
}
我在節點router.post
router.post('/customers', (req,res,next) =>{
let newCustomer = new Customer({
firstName: req.body.firstName,
lastName: req.body.lastName,
date: Date.now()
});
newCustomer.save(function(err, Customer){
if (err){
res.json({msg: 'Failed to add contact'});
}else{
res.json({msg: 'Customer added to waitlist'});
}
});
我的模型/架構爲客戶
const customerSchema = new Schema({
date: new Date();
firstName: {
type: String,
//required means there has to be a name
required: true
},
lastName: {
type: String,
required: true
}
});