Shows how to send data from app-child component to the app component, and in return send that data to the app-child2 component. So, you're emitting data from the app-child component to the app component. Taking that data and sending it to the app-child2 component.
Run npm run this for a dev server that will open http://localhost:4200/ in your browser.
- Import (Output, EventEmitter) from '@angular/core' into the child component.
- Create
@Output() nameOfEvent: EventEmitter<any> = new EventEmitter<any>()inside the child component. - Add
<app-child (nameOfEvent)="nameOfEvent($event)"></app-child>to the app-child component html block. - Create the
nameOfEventmethod inside of the app component ts file. - From the
nameOfEventmethod,this.nameOfEvent.emit('your string, boolean, object, etc'); - Create a variable
nameOfVariable: string = ''inside of the app component ts file. - Inside of the
nameOfEventmethod, set thenameOfVariableto the output of the app-child. - Inside of app-child2, import
Input from '@angular/core. - Add
@Input() nameOfVariable: string = ''inside of the app-child2 component. Optionally, display the nameOfVariable in the html of the app-child2 component, or whatever you need to do- That is how to pass data from
child to parent,parent to child, andchild to child