Question presented to candidate: "A star-rating component sits inside a product page. When the user picks a rating, how does the child tell the parent, and what exactly happens when it does?"
What a strong answer should cover:
- Data flows down through inputs and up through outputs; a child never reaches into its parent.
- Modern API:
rated = output<Rating>()andthis.rated.emit(value); the decorator form is@Output() rated = new EventEmitter<Rating>(). - The parent listens with event-binding syntax
(rated)="onRated($event)";$eventis the emitted value, not a DOM event. emit()is synchronous: the parent handler runs beforeemit()returns.- Outputs are not DOM events: they do not bubble to grandparents.
- An input named
xplus an output namedxChangeenables[(x)]two-way binding;model()creates both at once.
Clarifying questions expected:
- "Is the receiver the direct parent, or something further up or a sibling?" (the answer changes to a shared service)
Code / implementation expected: Yes β a child with an output and a parent handling it.