Angular - Child parent interaction

Child component

A component can have another component inside it, we refer it to as an child component.
Child component inside a parent component

Parent to child communication

For communication with the child component, the parent component can use input event emitter.For this we need to send the data and feed it to our child component

componentData is a input event emmiter and componentDataUser is the data that we feed to the child.The value of componentDataUser  will be passed to the child if we log the value we will see
"Hi".


Child to Parent communication

We can send back any data from child by using the output event emmiter

After this.switch.emit(initialize) is called in dynamictab.component.js then the variable initialize is sent to the component dynamictab.component.ts method switchCompData as parameter.If we log the value then it will show the value that we have passed from the child component it will display "Hi" in the web browser.


Comments