[英]Angular 2 - Change in One Component Not Triggering onChanges in Another
I am trying to get changes from one grid to flow into another, and subsequently update one of the rows in that underlying datasource. 我试图将更改从一个网格传递到另一个网格,然后更新该基础数据源中的行之一。 In the attached plunker, I basically want the underlying datasource of
Bar
to have the TotalSalary
row updated with the total salary that is calculated from Foo
. 在所附的插件中,我基本上希望
Bar
的基础数据源具有用Foo
计算的总薪水更新TotalSalary
行。 The total salary gets passed down upon hitting enter in the textbox. 在文本框中按Enter键后,总薪水将被向下传递。
I have gotten it working by emitting Foo.getSalaryTotal()
instead of Foo
itself; 我通过发出
Foo.getSalaryTotal()
而不是Foo
本身来使其工作。 however, I would prefer to pass through Foo
because I can foresee myself wanting multiple fields passed through and not wanting to have tons of inputs/ouputs. 但是,我更希望通过
Foo
因为我可以预见自己希望通过多个字段,并且不想拥有大量输入/输出。
http://plnkr.co/edit/4sw4yhzDTep4j0jGLDhD?p=preview http://plnkr.co/edit/4sw4yhzDTep4j0jGLDhD?p=预览
I recently answered almost the same question here . 我最近在这里回答了几乎相同的问题。
Since foosGrid
is being (re)set to the same foos
object in foosChanged()
, Angular will not notice the change because foosGrid
is still referencing the same object. 由于
foosGrid
被(重新)设置为foosChanged()
的同一foos
对象, foosChanged()
Angular将不会注意到更改,因为foosGrid
仍在引用同一对象。
One option is to implement ngDoCheck()
in your Bar
component and perform a custom check to see if the properties of the foos
object in Bar
have changed. 一种选择是在
Bar
组件中实现ngDoCheck()
并执行自定义检查,以查看Bar
foos
对象的属性是否已更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.