【发布时间】:2020-09-06 12:11:30
【问题描述】:
我正在使用 Angular,我正在尝试执行可重复使用的操作,例如批量更新、批量删除、批量停用。
我在另一个组件中使用了所有这些操作,并希望将其用作通用方法。
也就是说,我有两个组件:父组件和子组件。
父组件:
在父组件中,我正在使用一个表格(每行带有复选框)。 在复选框中我使用了一种方法,
rowDataCheck(event, rowData) {
if (event.target.checked) {
this.groupList.push(rowData);
} else {
this.groupList = this.groupList.filter(item => item.id !== rowData.id);
}
}
该值存储在grouplist[] 中。当页面加载(ngOnint)groupList=[]。
例如:-
1. when ngOnit() loads = this.grouplist=[];
2. when I check 1st row = this.grouplist=[1];
3. when I check 2st row = this.grouplist=[1,2];
4. Unchecking and checking changes the groupList value(conditions give above)
子组件:
选中复选框后,我想将 groupList 值传递给子组件。
问题::
为了将值从父级传递给子级,我使用了@input 方法。但是子组件仅在页面加载时才起作用。。每次选中复选框时,我都需要将值从父级传递给子级。
请查看stackblitz
【问题讨论】:
-
谁能帮帮我?
-
when the checkbox selects-> 订阅活动 -> 做你需要的事 -
“子组件仅在页面加载时工作”是什么意思。输入应该在父级更改关联值的任何时候起作用。你有在孩子上定义的 onPush 吗?我们可以提供一些代码示例吗?
-
@yoannAugen stackblitz.com/edit/…... 请检查这个.. 为了您的理解,我在子组件中使用了 console.log。
标签: angular typescript angular6 angular5