5

I want to use ngIf and ngFor in one line. I know it is not possible but is there any other method to do this?

Here is my code:

<option *ngIf="tmpLanguage.id!=languages.id" 
        *ngFor="let tmpLanguage of languages" [ngValue]="tmpLanguage.id">
     {{tmpLanguage.identificatie}}
</option>
yurzui
  • 190,482
  • 29
  • 403
  • 383
C.B.
  • 310
  • 1
  • 2
  • 16

2 Answers2

37

Only one structural directive is allowed on one element at a time.

As a workaround you can use <ng-container> which is not stamped to the DOM

<ng-container *ngFor="let tmpLanguage of languages">
  <option *ngIf="tmpLanguage.id!=languages.id"  [ngValue]="tmpLanguage.id" >{{tmpLanguage.identificatie}}</option>
</ng-container>
Günter Zöchbauer
  • 558,509
  • 191
  • 1,911
  • 1,506
3
<ng-container *ngFor="let tmpLanguage of languages">
  <option *ngIf="tmpLanguage.id!=languages.id" [ngValue]="tmpLanguage.id" >
    {{tmpLanguage.identificatie}}
  </option>
</ng-container>
yurzui
  • 190,482
  • 29
  • 403
  • 383