$scope.addMedication = function(med) {
$http.post('/medications', {
name: med.name,
slug: med.slug,
description: med.description
}).success(function(medication) {
$scope.newMedicationTitle = '';
$scope.medications.push(medication);
}).error(function(err) {
// Alert if there's an error
return alert(err.message || "an error occurred");
});
};
拥有此代码。我想发布整个对象而不使用单独的字段。我怎么能这样做?
答案 0 :(得分:0)
就像那样:
$scope.addMedication = function(med) {
$http.post('/medications', med).success(function(medication) {
$scope.newMedicationTitle = '';
$scope.medications.push(medication);
}).error(function(err) {
// Alert if there's an error
return alert(err.message || "an error occurred");
});
};