Javascript Angular4:如何将对象数组传递给函数
我想通过对象数组在角度4中运行 调用函数: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
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更新问题