Forms in Angular
Forms are used to gather input from users in an Angular application. Here is an example of a template-driven form in Angular:
<form #myForm="ngForm" (ngSubmit)="onSubmit(myForm.value)">
<div>
<label for="name">Name:</label>
<input type="text" id="name" name="name" ngModel required>
</div>
<div>
<label for="email">Email:</label>
<input type="email" id="email" name="email" ngModel required>
</div>
<button type="submit">Submit</button>
</form>
This code sets up a form with two input fields for the user's name and email, and a submit button that triggers the onSubmit function.
No comments:
Post a Comment