Angular trying to use ngModel on html element

Issue

What Im trying is this:

    <div class = "form-group">
  <label for="funktion">Funktion</label>
  <select formControlName="funktion" id="funktion" class="form-control" ngModel #Funktion="ngModel" required >
    <option *ngFor="let Funktion of funktionen" value="{{Funktion.Name}}">{{Funktion.Name}}</option>
  </select>
</div>
<div *ngIf="Funktion.value == 'Administrator' ">
  Some Text here
</div>

But it get the following error:

There is no directive with “exportAs” set to “ngModel” (” ]#Funktion=”ngModel” required >

My Goal is to show the if the Funktion with the value “Administrator” is slected on the dropdown and hide it if “Administrator” is not selected…

What am I doing wrong?

Solution

  <div class = "form-group">
      <label for="funktion">Funktion</label>
      <select formControlName="funktion" id="funktion" [(ngModel)]="Funktionname" class="form-control"  required >
       <option *ngFor="let Funktion of funktionen" value="{{Funktion.Name}}">{{Funktion.Name}}</option>
      </select>
  </div>
  <div *ngIf="Funktionname == 'Administrator' ">
    Some Text here
  </div>

Answered By – sebu

Answer Checked By – Gilberto Lyons (AngularFixing Admin)

Leave a Reply

Your email address will not be published.