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 に答える