我正在開發一個管理客戶信息的應用程序。我是新來的MEAN堆棧,並不能爲我的生活弄清楚我在這裏做錯了什麼。當我從視圖中單擊「更新客戶」時,控制檯將打印更新的信息,但是當我嘗試將該信息發送到服務器並更新我的表格時,我什麼也得不到。客戶實體保持與以前一樣。
認爲
<div class="col-sm-12" id="addButton" style="padding: 10px;" >
<button
class="btn btn-primary"
ng-click="update()"
ng-disabled="editCustomerForm.$invalid">Update Customer</button>
控制器
$scope.update = function(){
console.log($scope.existingCustomer);
$http.put('/customers/' + $scope.existingCustomer._id, $scope.existingCustomer).success(function(response) {
refresh();
$scope.existingCustomer={};
$scope.editOldCustomer = false;
})
};
server.js文件
app.put('/customers/:id', function (req, res) {
console.log(req.body);
var id = req.params.id
db.customers.findAndModify({
query: {_id: "mongojs.ObjectId(id)"},
update: {$set: {name: req.body.name, email: req.body.email, phone: req.body.phone,
street: req.body.street, city: req.body.city, state: req.body.state, zip: req.body.zip}},
new: true}, function (err, doc) {
res.json(doc);
}
);
});
我一直令人頭大我的大腦與此幾個小時,強制噸無法弄清楚我做錯了什麼。感謝您的幫助,我真的很感激。對不起,如果一些代碼的格式化搞砸堆棧
什麼客戶端或ORM用於與您的MongoDB實例進行交互? –
我通過sudo安裝monogojs npm mongojs安裝 – jpstearns
git repo是https://github.com/jpstearns/customerApp – jpstearns