form submit in angular code example

Example 1: ngForm

<form #f="ngForm" (ngSubmit)="onSubmit(f)" novalidate>
  <input name="first" ngModel required #first="ngModel">
  <input name="last" ngModel>
  <button>Submit</button>
</form>

<p>First name value: {{ first.value }}</p>
<p>First name valid: {{ first.valid }}</p>
<p>Form value: {{ f.value | json }}</p>
<p>Form valid: {{ f.valid }}</p>

Example 2: form in angular

//import in app.module.ts file
npm i @angular/forms
import {FormsModule} from "@angular/forms"

.
.
.

imports:[... FormsModule],

Tags:

Html Example