title: ERROR TypeError: Cannot read property 'invalid' of undefined angular 4
body: <p>I am getting the following error in Angular 4 :</p>
  
  <blockquote>
    <p>ERROR TypeError: Cannot read property 'invalid' of undefined</p>
  </blockquote>
  
  <p>Here's the code :</p>
  
  <pre><code>&lt;form name="form"  #f="ngForm" novalidate&gt;
  
    &lt;tr&gt;
       &lt;td width="10%" class="text-blue"&gt;&lt;/td&gt; 
       &lt;td&gt;&lt;input type="text"  name="bankname" maxlength="25" appRestrictinput ="words" [(ngModel)]="model.bk_name" #bk_name="ngModel"  class="form-control" autofocus  /&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;div *ngIf="bankname.invalid &amp;&amp; (bankname.dirty || bankname.touched)" class="alert alert-danger"&gt;
       &lt;div *ngIf="bankname.errors.required"&gt;Name is required&lt;/div&gt;
    &lt;/div&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>Please let me know where I'm going wrong. Thanks in advance.</p>