0
$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");
    });
  };

有这个代码。我想发布整个对象而不使用单独的字段。我怎么能做到这一点?

4

1 回答 1

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");
    });
  };
于 2016-03-01T20:39:08.837 回答