Search code examples
angularjspostwebdeployddpd

angular post method with deployd


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

Have this code. I want to post the entire object without using separate fields. How I can do this?


Solution

  • Like that:

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