In this lecture, we were going to handle the form submission with a custom event emitted by the form
group object.
There's already an event for listening to submission events.
Despite the availability of this event, Angular introduces a custom event for listening to submission
events.
Let's explore the differences.
Open the register component template file.
On the form element, we are going to bind to events called submit and nji submit.
Both events will get triggered on form submission, the submit event is the default browser submission
event.
The Nji Submit Event is a custom event by Angular.
There's one small difference between the two events.
The Nji submit will automatically stop the browser from refreshing when the form is submitted.
This step needs to be performed manually.
If we use the submit event, you can think of it as a shorthand way of listening for submission events
while preventing the default behavior for obvious reasons.
We are going to use the Nji Submit event.
Let's remove the submit event.
Let's run the function on the Nag submit event, the name of the function will be called register.
Typically, we would pass on the event, object onto the function, since the nji submit event prevents
the default behavior, we can skip this step.
This function doesn't exist.
Let's define it.
Open the register component class file.
Inside the class defined the register function.
We are going to keep it simple by logging a message.
Let's try testing out the submission in the browser.
We are going to need to fill out the form by pressing the submit button.
After submitting the form, nothing happens, let's check out the console in the developer tools.
The message from the register function gets logged as long as the page isn't refreshing.
We should be good to go.
If the page refreshed, the user would have to fill out the form again.
Behind the scenes, we should submit their data to a server.
We will handle this step in another section.
For now, we've successfully submitted the form.
There's one last feature I want to add to the registration form.
Users should be given feedback while they wait.
Let's work on providing submission feedback in the next lecture.