Event binding
- ✔️Event bindingLearn how to bind an event to a function in Angular
Event binding
Event binding allows to listen to events and execute a function when the event is triggered. In the current situation, you want to execute a function when the ‘create task’ button is clicked.
On the html button tag, you can bind the click event to a function using the (click)
syntax.
You assign it the function you want to execute when the button is clicked.
This function will be created in the component class.
🎓 Instructions
-
Replace the content of the
src/app/task-form/task-form.component.html
file.
createTask function
You will create a createTask function to handle the form submission. For this step, let’s just log the form value to the console.
🎓 Instructions
-
Update the
src/app/task-form/task-form.component.ts
file.
- Open the devtools console in your browser.
- By clicking on the ‘create task’ button, you should see the form data logged to the console.
🌱 Challenge
Fill the title and description fields and click on the ‘create task’ button. Verify that the form value logged to the console is updated.
✔️ What you learned
You learned how to listen to an event to trigger a function.