javascript - 可以在 Angular JS 的 HTTP post 请求中传递多个 $scope 变量吗?

标签 javascript angularjs

  $scope.getQuery = function() {
    var response =  $http.post('/test/getQuery', $scope.query, $scope.algoName);
    response.success(function(data, status, headers, config) {
           console.log($scope.query);           
           console.log($scope.algoName);
        });
   }

这里我传递了$scope.query, $scope.algoName。这在 AngularJS 中可能吗?

最佳答案

您可以将它们作为 data 传入参数$http.post()接受:

var data = {
    query: $scope.query,
    algoName: $scope.algoName
};

$scope.getQuery = function() {
    var response =  $http.post('/test/getQuery', data);
    response.success(function(data, status, headers, config) {
        console.log($scope.query);
        console.log($scope.algoName);
    });
};

这些将作为请求消息数据发送。

关于javascript - 可以在 Angular JS 的 HTTP post 请求中传递多个 $scope 变量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31699175/

相关文章:

javascript - 在 Chrome 等中进行 Canvas 操作(fillRect() 等)时内存消耗的问题

javascript - cron 中的 Promise 只执行一次

javascript - 为 AngularJS 中的列分配颜色

javascript - 我的所有模板都在 $templateCache 中,但 Angular 仍然在发出请求

angularjs - Angular-Fullstack 需要外部模块 babel-register

javascript - 使用 ExtJS 获取特定类型的所有元素

javascript - 根据鼠标指针改变div的位置

javascript - jQueryUI Draggable ,触发 "stop"事件

javascript - 数据表刷新按钮和旋转很棒的图标

javascript - 过渡期间 AngularJS SubForm 的性能