In an attempt to connect the model in angular template-driven forms, I have created a model class and utilized it to fill the input field.
HTML:
<div class="form-group col-md-2 col-12" [class.text-danger]="nameCode.invalid && nameCode.touched">
<label for="inputName" class="form-control-label"> Name</label>
<input type="text" class="form-control" [class.is-form-invalid]="nameCode.invalid && nameCode.touched" id="inputName" name="lotCode"[(ngModel)]="formModel.name" #nameCode="ngModel" aria-describedby="nameHelp" autocomplete="new-password" required>
<small id="nameHelp" class="text-danger" *ngIf="nameCode.invalid && nameCode.touched">Required</small>
Component:
export class AppComponent {
formModel: FormModel= new FormModel();
}
export class FormModel {
name: "abc"
}
https://stackblitz.com/edit/angular-yue9fe?file=src%2Fapp%2Fapp.component.ts