A client asks for a feature where a child component should be able to inform its parent component when a button inside the child component is clicked. How would you implement this interaction?

  • Use the @Output decorator to emit an event from the child component and bind to it in the parent component.
  • Use the @ViewChild decorator to access the child component's method directly from the parent component.
  • Use the @Input decorator to pass a callback function from the parent to the child component.
  • Use the @HostListener decorator to listen for events in the child component and trigger a method in the parent component.
To implement communication from child to parent in Angular, you can use the @Output decorator to emit an event from the child component, and the parent component can bind to this event to listen for changes. This allows the child to inform the parent when the button is clicked. The other options are not the typical approach for this scenario.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *