如何将新值绑定到数组变量从一个组件到另一个组件以及第一个组件中的现有数据 [英] how to bind the new values to array variable from one component to another component along with existing data's in first component

查看:48
本文介绍了如何将新值绑定到数组变量从一个组件到另一个组件以及第一个组件中的现有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个组成部分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共享数据

这篇关于如何将新值绑定到数组变量从一个组件到另一个组件以及第一个组件中的现有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆