I am working on the form validation. I am using template-driven validation form whose coding is below. Its working fine now but when I try to add #username = "ngModel" and #password = "ngModel" in input to create validation classes it's showing me an error. Please find the error also.
<div class="container">
<div class="row">
<div class="centering text-center">
<div class="login-cont col-md-4 col-md-offset-4 vcenter">
<form id="login_form" name="login-form" #f="ngForm" role="form" (ngSubmit)="f.form.valid && login()" novalidate>
<input id="username" [(ngModel)]="username" name="username" required class="form-control" type="text" placeholder="Username" >
<input id="userPassword" class="form-control" required type="password" name="userPassword" required placeholder="Password" [(ngModel)]="password" >
<button type="submit" class="btn login-btn">Login</button>
</form>
</div>
</div>
</div>
</div>
Cannot assign to a reference or variable!
at _AstToIrVisitor.visitPropertyWrite (webpack-internal:///../../../compiler/esm5/compiler.js:26226:23)
at PropertyWrite.visit (webpack-internal:///../../../compiler/esm5/compiler.js:4803:24)
at convertActionBinding (webpack-internal:///../../../compiler/esm5/compiler.js:25676:45)
at eval (webpack-internal:///../../../compiler/esm5/compiler.js:28166:22)
at Array.forEach (<anonymous>)
at ViewBuilder._createElementHandleEventFn (webpack-internal:///../../../compiler/esm5/compiler.js:28162:18)
at nodes.(anonymous function) (webpack-internal:///../../../compiler/esm5/compiler.js:27581:27)
at eval (webpack-internal:///../../../compiler/esm5/compiler.js:28107:22)
at Array.map (<anonymous>)
at ViewBuilder._createNodeExpressions (webpack-internal:///../../../compiler/esm5/compiler.js:28106:56)
This is what I tried but it gives me an error
<input id="username" class="form-control" type="text" required name="username" placeholder="Username" [(ngModel)]="username" minlength="4" #names="ngModel">
<div *ngIf="names.invalid && (names.dirty || names.touched)"
class="alert alert-danger">
</div>
<div *ngIf="names.errors.required">
Name is required.
</div>
<div *ngIf="names.errors.minlength">
Name must be at least 4 characters long.
</div>