How does a child component send data to its parent?
Model answer
The child declares an output and emits events. In current Angular: saved = output<string>() and then this.saved.emit(value). In the parent template you listen with (saved)="onSaved($event)". The classic style uses @Output() with an EventEmitter.
Keep the pattern simple: data down with inputs, events up with outputs. For siblings or distant components, use a shared service.
Learn this topic
Angular Tutorial: Beginner to Advanced .
Sign in to add your own answer.
More questions
- What are the parts of a component?
- What is data binding? Explain the four types.
- What is the difference between interpolation and property binding?
- How do you pass data from a parent component to a child component?
- What is the component lifecycle? Describe the main hooks.
- What is the difference between the constructor and ngOnInit?