Search code examples
angularangular2-ngmodelngmodel

Angular trying to use ngModel on html element


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>