Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular4:如何将对象数组传递给函数_Javascript_Arrays_Angular - Fatal编程技术网

Javascript Angular4:如何将对象数组传递给函数

Javascript Angular4:如何将对象数组传递给函数,javascript,arrays,angular,Javascript,Arrays,Angular,我想通过对象数组在角度4中运行 调用函数: this.clickCounter(this.persons); persons=[ {name:"ali",mobile:"1234"}, {name:"ahmed",mobile:"1234"}, {name:"noha",mobile:"1234"}, {name:"esam",mobile:"1234"}, ] 我的阵列: this.clickCounter(this.persons); persons=[ {name

我想通过对象数组在角度4中运行

调用函数:

this.clickCounter(this.persons);
persons=[
  {name:"ali",mobile:"1234"},
  {name:"ahmed",mobile:"1234"},
  {name:"noha",mobile:"1234"},
  {name:"esam",mobile:"1234"},
]
我的阵列:

this.clickCounter(this.persons);
persons=[
  {name:"ali",mobile:"1234"},
  {name:"ahmed",mobile:"1234"},
  {name:"noha",mobile:"1234"},
  {name:"esam",mobile:"1234"},
]
功能

clickCounter(x:any[]) {
  console.log("data in function " + x);
}
控制台:

this.clickCounter(this.persons);
persons=[
  {name:"ali",mobile:"1234"},
  {name:"ahmed",mobile:"1234"},
  {name:"noha",mobile:"1234"},
  {name:"esam",mobile:"1234"},
]

您发送数据的代码正常,但问题在于
日志

更改:
console.log(“函数中的数据”+x)

console.log(“函数中的数据”,x),


正如
+
一样,它严格地被数组覆盖,所以请将其删除。

似乎没有问题,您是否有任何错误?您是否真的在问如何从组件中的http服务(网站)获取该数组?请继续键入
any
或为其创建一个带有属性name和mobile的接口
Person
。然后,您可以使用
Person[]
Array
@Nico Van Belle,我做了,但仍然可以通过控制台打印屏幕@anoop使用samei更新问题