在AngularJS中使用$http服务发布多个阵列

在AngularJS中使用$http服务发布多个阵列,angularjs,node.js,javascript,Angularjs,Node.js,Javascript,我正在使用和有两个阵列,我想发布到服务器上,以进行处理并在确认电子邮件中发送。您对如何正确提交这些数组有何想法 以下是两个数组: var array1 = vm.contacts; var array2 = vm.projects; data = array1; // Is it possible to add array2 here too? $http.post('http://localhost:9000/api/emails', data) .then(function(resp

我正在使用和有两个阵列,我想发布到服务器上,以进行处理并在确认电子邮件中发送。您对如何正确提交这些数组有何想法

以下是两个数组:

var array1 = vm.contacts;
var array2 = vm.projects;
data = array1; // Is it possible to add array2 here too?

$http.post('http://localhost:9000/api/emails', data)
  .then(function(response) {
      console.log(response);

    }, function(response) {
      console.log('error', response);
    }
$http.post('http://localhost:9000/api/emails', data)
    .then(function (response) {
    console.log(response.data); // Use response.data to show your response.
}, function (response) {
    console.log('error', response);
}
$http.post('http://localhost:9000/api/emails', data)
    .then(function (response) {
    console.log(response.data); // Use response.data to show your response.
}, function (response) {
    console.log('error', response);
}
$http服务:

var array1 = vm.contacts;
var array2 = vm.projects;
data = array1; // Is it possible to add array2 here too?

$http.post('http://localhost:9000/api/emails', data)
  .then(function(response) {
      console.log(response);

    }, function(response) {
      console.log('error', response);
    }
$http.post('http://localhost:9000/api/emails', data)
    .then(function (response) {
    console.log(response.data); // Use response.data to show your response.
}, function (response) {
    console.log('error', response);
}
$http.post('http://localhost:9000/api/emails', data)
    .then(function (response) {
    console.log(response.data); // Use response.data to show your response.
}, function (response) {
    console.log('error', response);
}

您可以发送包含这些数组的对象。大概是这样的:

var vm = {};
vm.contacts = []; // Array of contacts.
vm.projects = []; // Array of projects.
var data = vm; // Object with arrays.
var vm = {};
vm.contacts = [];
vm.projects = [];

var arrays = [];
var array1 = vm.contacts;
var array2 = vm.projects;

arrays.push(array1, array2);
console.log(arrays);
var data = arrays;
在您的$http服务中:

var array1 = vm.contacts;
var array2 = vm.projects;
data = array1; // Is it possible to add array2 here too?

$http.post('http://localhost:9000/api/emails', data)
  .then(function(response) {
      console.log(response);

    }, function(response) {
      console.log('error', response);
    }
$http.post('http://localhost:9000/api/emails', data)
    .then(function (response) {
    console.log(response.data); // Use response.data to show your response.
}, function (response) {
    console.log('error', response);
}
$http.post('http://localhost:9000/api/emails', data)
    .then(function (response) {
    console.log(response.data); // Use response.data to show your response.
}, function (response) {
    console.log('error', response);
}
更新:

var array1 = vm.contacts;
var array2 = vm.projects;
data = array1; // Is it possible to add array2 here too?

$http.post('http://localhost:9000/api/emails', data)
  .then(function(response) {
      console.log(response);

    }, function(response) {
      console.log('error', response);
    }
$http.post('http://localhost:9000/api/emails', data)
    .then(function (response) {
    console.log(response.data); // Use response.data to show your response.
}, function (response) {
    console.log('error', response);
}
$http.post('http://localhost:9000/api/emails', data)
    .then(function (response) {
    console.log(response.data); // Use response.data to show your response.
}, function (response) {
    console.log('error', response);
}
通过这种方式,您可能需要发送数组的数组。大概是这样的:

var vm = {};
vm.contacts = []; // Array of contacts.
vm.projects = []; // Array of projects.
var data = vm; // Object with arrays.
var vm = {};
vm.contacts = [];
vm.projects = [];

var arrays = [];
var array1 = vm.contacts;
var array2 = vm.projects;

arrays.push(array1, array2);
console.log(arrays);
var data = arrays;
然后:

在您的$http服务中:

var array1 = vm.contacts;
var array2 = vm.projects;
data = array1; // Is it possible to add array2 here too?

$http.post('http://localhost:9000/api/emails', data)
  .then(function(response) {
      console.log(response);

    }, function(response) {
      console.log('error', response);
    }
$http.post('http://localhost:9000/api/emails', data)
    .then(function (response) {
    console.log(response.data); // Use response.data to show your response.
}, function (response) {
    console.log('error', response);
}
$http.post('http://localhost:9000/api/emails', data)
    .then(function (response) {
    console.log(response.data); // Use response.data to show your response.
}, function (response) {
    console.log('error', response);
}

你为什么不创建一个包含这两个数组的数组并发送出去?@Luke P.Issac我正在从Firebase数据库中获取两个单独的数组。我不确定如何创建这两个数组的数组。我想这是问题的一部分。