如何将新值绑定到数组变量从一个组件到另一个组件以及第一个组件中的现有数据

如何将新值绑定到数组变量从一个组件到另一个组件以及第一个组件中的现有数据

问题描述:

我有两个组成部分comp1&comp2

i has two components comp1 & comp2

comp1具有一个数组变量.我在comp2中创建了构造函数以供comp1访问comp1函数它可以正常工作,并且值绑定在我绑定的同一数组变量中.

comp1 has one array variable . i created constructor in comp2 for comp1 to access comp1 functions it is workiing correctly and the values are binding in same array variable which i binds.

我需要将comp2中的值与comp1中数组变量中的现有数据绑定在一起

i need to bind the value from comp2 along with existing datas in the array variable in comp1

comp1中的数组变量已经有一些值.

Array variable in comp1 has some values already.

但是我的问题是当我从comp2绑定相同变量的值时,这些值被保持分别不包含该数组变量中的现有数据

but my problem is when i binding the value from comp2 for the same variable the values are maintaing seperately not with existing datas in that array variable

如何将新值与现有数据绑定到comp1变量

how to bind the new values to comp1 variable along with existing datas

我认为您可以直接将数据分配到 comp1 中.这样.

I think you may directly assign data into comp1. Like this.

array1 = values;

相反,请这样做

array1.push(values);

它将在现有数组中添加值.

It will add values in existing array.

并确保您以正确的方式输入了Passig数据.

And make sure you are passig data in correct way.

子对父:通过ViewChild共享数据