How do you pass data from a parent component to a child component?
Model answer
Mark a property in the child as an input and bind it in the parent's template. In current Angular you write name = input<string>() in the child, and in the parent <app-child [name]="userName" />. The child reads it as name() because inputs created with input() are signals. In the classic style you use the @Input() decorator on a property.
Data flows down through inputs. The child sends information up with outputs.
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 does a child component send data to its parent?
- What is the component lifecycle? Describe the main hooks.
- What is the difference between the constructor and ngOnInit?