我是Angular的新手,我正在尝试实现事件的日历。我正在使用Angular UI日历。当我发布数据时,它会发布但会出现错误。
帖子方法
$http({
method : 'POST',
url : '/api/appointment',
data : $scope.appointment
}).success(function(data) {
console.log(data);
}).error(function(err) {
console.log(err);
});
预期数组但收到:
{ "__v": 0,
"visitType": "Referral",
"timeDuration": "900000",
"patientId": "BMSHT002",
"doctorId": "BMSHTDOC60",
"_id": "5833da8d9889edd037a54c30",
"eventSources": [{
"title": "Patient Name : Vignesht Age :10t Gender : malet Email Id : bvikcy.2205@gmail.comn Appointment Type : Referraln Doctor Name : Demo 1",
"start": "2016-11-21T04:30:00.000Z",
"end": "2016-11-21T04:45:00.000Z",
"_id": "5833da8d9889edd037a54c31"
}]
}
我知道这是一个JSON数据,但是我不确定如何解决此问题。有人可以帮我解决这个问题吗?
这是我在发布数据时正在使用的模式
var appointmentSchema = mongoose.Schema({
patientId : String,
doctorId : String,
visitType : String,
timeDuration : String,
eventSources: [{
title : String,
start : Date,
end : Date
}]
});
节点JS代码
router.route('/appointment')
.post(function(req, res) {
var appointmentData = req.body;
var appointments = new Appointment(appointmentData);
console.log(appointments);
appointments.save(function(err, appointment) {
if (err)
throw err;
res.send(appointment);
})
})
预先感谢
而不是'res.send',请尝试'res.json'如下
router.route('/appointment')
.post(function(req, res) {
var appointmentData = req.body;
var appointments = new Appointment(appointmentData);
console.log(appointments);
appointments.save(function(err, appointment) {
if (err)
throw err;
res.json(appointment);
})
})