I have added the FormsModule in the component module and also tried by adding it to the app module but the same error is repeating 4 times in the console. Please help me fix this issue.
grant-access.component.html
<form #grantAccessForm="ngForm" (ngSubmit)="onSubmit(grantAccessForm)">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input
type="text"
class="form-control form-control-alternative"
ngModel
name="clientName"
placeholder="Client Name"
/>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input
type="text"
placeholder="IMD Code"
class="form-control form-control-alternative"
ngModel
name="imdCode"
/>
</div>
</div>
</div>
<div class="row justify-content-center">
<div class="col-3 col-md-2">
<button class="btn btn-primary">Submit</button>
</div>
</div>
</form>
grant-access.component.ts
import { Component, OnInit } from '@angular/core';
import { NgForm } from '@angular/forms';
@Component({
selector: 'app-grant-access',
templateUrl: './grant-access.component.html',
styleUrls: ['./grant-access.component.scss']
})
export class GrantAccessComponent implements OnInit {
constructor() {}
ngOnInit() {
}
onSubmit(form){
console.log(form)
}
}
Thanks in advance
You need a two-way data binding for template driven forms. Use
[(ngModel)]="dataModel.clientName"where data model is your object model.And in your
component.ts