Z
Z
zlodiak2018-09-01 16:47:17
Angular
zlodiak, 2018-09-01 16:47:17

How to receive only new incoming data in a child component?

There are parent and child components. The parent has two buttons and a variable. When the first button is clicked, the value "4" is assigned to the variable. When another button is clicked, the variable is assigned the value "2" The
child component gets this value of this variable through an attribute like so:

<hello [isVisibleDatepicker]="isVisibleDatepicker"></hello>

and outputs with a hook:
ngAfterViewChecked() {
    console.log('--------', this.isVisibleDatepicker);
  }

I would like to make the child component output only the new values, not every one. That is, if the user clicked three times on the first button, then the child component displayed the value "4" only once. Please help me implement this.
Demo here

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-09-01
@zlodiak

That is, if the user clicked three times on the first button, then the child component displayed the value "4" only once.

And if you clicked on the first, then on the second, and then again on the first? What should be output to the console? If 4-2-4 then use ngOnChanges to display the values. If 4-2-nothing - add an array to the child component, where you will add the output values, and before output, check if there is what you are going to send to the console.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question