ERROR TypeError: Cannot read property 'invalid' of undefined angular 4
You Just forgot about Template variable
Add this to your input #bankname="ngModel" and it will work with you
<input ngModel name="bankname" type="text" #bankname="ngModel" class="form-control" placeholder="Name" required> <br/>
<div class="alert alert-danger" *ngIf="bankname.invalid">bankname is required</div>
Your control reference in the view is bk_name
. Replace bankname
with bk_name
.
<div *ngIf="bk_name.invalid && (bk_name.dirty || bk_name.touched)" class="alert alert-danger">
<div *ngIf="bk_name.errors.required">Name is required.</div>