Angular: Error no directive with “exportAs” set to “ngForm”

The error was caused by this line:

#inputSearch="ngForm"

This is the correct line:

#inputSearch="ngModel"

Here is the working example. When you use ngModel within the form tag you also need to provide value for the “name” attribute.

  <form #searchForm="ngForm">
  <input type="text" required name="search" [(ngModel)]="model.search"  #inputSearch="ngModel">
  <p class="error" [hidden]="inputSearch.valid"> This input is required</p>
  </form>

Leave a Comment