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.