简体   繁体   English

角度2-一个组件的更改不会触发另一组件的onChange

[英]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.

相关问题 Angular.io / Angular 4.如何在触发另一个组件视图时刷新它 - Angular.io / Angular 4. How do I refresh one component view when triggering another 无法从 angular 中的另一个组件更改一个组件的属性值 - unable to change an attribute value of one component from another component in angular 如何在Angular 5中将一个组件的变量更改为另一个组件的变量 - How to change variable of one component from another component in Angular 5 如何跟踪 Angular 中另一个组件中一个组件中发出的值的变化 - How to track change of a value emitted in one component in another component in Angular 您可以在Angular 2组件中同时使用OnChanges和DoCheck吗? - Can you use both OnChanges and DoCheck in an Angular 2 component? 为什么一个带有自定义指令的元素会在 Angular 中触发另一个元素更改事件? - Why is one element with custom directive triggering another elements change event in Angular? 角度2-将类别从一个组件更改为另一个组件 - Angular 2- change class from one component to another 如何使用OnChanges angular来更改背景颜色? - How to use OnChanges angular in order to change background color? 对组件类函数的 Angular ng-change 调用不会触发 - Angular ng-change call to a Component Class function not triggering angular onChanges highcharts - angular onChanges highcharts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM