Component output
Component output
One key feature of reusable components is to notify the parent component that an action has been performed.
In the AlertBanner
component, we want to add a button, triggering a different action based on its usage:
- in the
TaskList
component, we want to call a function to delete all tasks - in the
TaskForm
component, we want to update the form with basic information
To do so, we’ll use the output
feature of Angular.
Define the output
Instructions
-
Update the
AlertBannerComponent
class:import { output } from '@angular/core';onSubmit = output<void>(); -
Update the template of
alert-banner.component.ts
file:<button (click)="onSubmit.emit()">Submit</button> -
Update the
TaskListComponent
class:deleteAllTasks() {// TODO: delete all tasks} -
Update the template of
task-list.component.ts
file:<app-alert-banner (onSubmit)="deleteAllTasks()" /> -
Update the
TaskFormComponent
class:preFillForm() {// TODO: pre fill the form with basic information} -
Update the template of
task-form.component.ts
file:<app-alert-banner (onSubmit)="preFillForm()" /> -
Test the application.