I'm having trouble implementing the client side update CRUD logic. The fields are currently being deleted with the set up as it is. What am I missing?
My angular:
$scope.editService = function(id) {
$http.put('/api/hc/' + id,
{title: 'new',
shortname: 'new',
summary: 'new',
description: 'new'}
)
.success(function(data) {
})
.error(function(data) {
console.log('Error: ' + data);
});
};
My express: Nothing seems to be getting passed the the JSON values, for some reason all of the fields and keys are wiped clean, leaving only the _id and _v keys and values.
.put(function(req, res) {
Service.findById(req.params._id, function(err, service) {
if (err)
res.send(err);
service.title = req.body.title; // update the items info
service.summary = req.body.summary;
service.shortname = req.body.shortname;
service.description = req.body.description;
// save the items
service.save(function(err) {
if (err)
res.send(err);
res.json({ message: 'Service updated!' });
});
});
})
My view
<form name="editForm" ng-submit="editService(service._id)" ng-repeat="service in services
filter:json">
<input type="text" placeholder="{{ service.title}}" ng-model="serviceTitle" required>
<input type="text" placeholder="{{ service.shortname}}" ng-model="serviceShortname" required>
<input type="text" placeholder="{{ service.description}}" ng-model="serviceSummary" required>
<textarea type="text" placeholder="{{ service.summary}}" ng-model="serviceDescription" required></textarea>
<button type="submit">Edit</button>
</form>
You're not actually putting data in the example you gave.
$http.put('/api/hc/' + id)
should be
$http.put('/api/hc/' + id, formData)
where formData is whatever object you glean from the form fields you want to send up the pipe. Also, have a gander at angular's $[resource][1] service, it's a much cleaner (imo) way to do REST clients than using $http directly.