jaroApp jaroApp - 1 year ago 120
AngularJS Question

Angular 2RC4 setter (or detect changes)

my goal is run action on component B when in component A was action. Of course component A emit event and this is input for component B. It works but not everyitme.

Look at the


When user click delete from component A one element is removed and event is emit. In component B I display same list (and it works). But also when is use function set list in component

should be increment. It is increment only after init and first remove.

I don't know why. How can I force this increment each time when
is changing?

Thanks in advance for any help.

Answer Source

This is expected behavior. The output emits the same array several times. Only the first time is it recognized as changed (from null to array). Subsequently when the same array is emitted again, change detection doesn't dedect it as change and no update is happening and therefore not call of the setter.

If you create a copy of the array after each modification using

this._list = this._list.slice();

then each change is recognized because slice() creates a new array instance.

Plunker example

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download