Update component / object Angular 6

0

I have 3 components that exchange an object with each other, how do I when to update one another also update alone?

Example: I have components 1, 2 and 3, 1 calls 2 by passing an object and 2 calls 3 by passing the same object, all this in the creation of components. I have to update component 3 when the object in component 1 changes.

    
asked by anonymous 24.10.2018 / 19:31

1 answer

0

To do this you should use @Input, moving from parent to child the value you want.

In this example you gave, the properties of components 2 and 3 must have the @Input annotation, so parents can 'input' the value into the children. Component inputa in 2, 2 inputa in 3, so only 2 and 3 need the @Input. And so on.

To send the children's value to parents, you must use @Output.

The detailed how to use @Input and @Output in the Angular site: link

I've made an example for you to see working: link

    
02.11.2018 / 04:23