Lotus@ 2016-04-20 00:55 采纳率: 100%
浏览 27

将Angular模型发送到后端

I have various inputs that call this function when they are changed:

$scope.updateOutputData = function(){
    // gathering data and making data object
    $scope.selectionObject = {
      "departure_city" : departureCityDigest,
      "departure_country" : departureCountryDigest,
      "budget_min" : $scope.budget.min,
      "budget_max" : $scope.budget.max,
      "person_count" : $scope.selectedPersonCount,
      "currency" : $scope.selectedCurrency,
      "month" : $scope.selectedMonth,
      "year" : $scope.selectedYear,
      "flight_duration_min" : $scope.flightDuration.min,
      "flight_duration_max" : $scope.flightDuration.max
    };

    // implement functionality to send this object to be read by backend

}

Basically this function gathers all input data and afterward it should send that object to backend, so in backend I can process this data and then depending on it, return back JSON API with data from database.

I do not know how to code this. I added comment in the bottom of my method. There should be code that sends data to backend and expects some JSON API to be returned. How would that code look like?

  • 写回答

2条回答 默认 最新

  • weixin_33686714 2016-04-20 01:00
    关注
    $http.post(ENDPOINT, $scope.selectionObject).then(function(success) { /* awesome */ }, function(error) { /* error */ });
    

    Sorry typed this using my iPhone. Don't forget to inject $http in your controller. And substitute ENDPOINT by your API URL.

    评论

报告相同问题?