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.
Loading...
Related Quiz
- In the Angular router, what is the purpose of the pathMatch property?
- In Jasmine, what function is used to group together related test cases?
- How do you set default values for controls in a reactive form?
- What is the role of Value Accessors in Angular forms?
- Which command in Angular CLI generates a new service?