Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ngIf and ngFor in option [duplicate]

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>
like image 391
C.B. Avatar asked Sep 19 '16 10:09

C.B.


2 Answers

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>
like image 80
Günter Zöchbauer Avatar answered Oct 01 '22 10:10

Günter Zöchbauer


<ng-container *ngFor="let tmpLanguage of languages">
  <option *ngIf="tmpLanguage.id!=languages.id" [ngValue]="tmpLanguage.id" >
    {{tmpLanguage.identificatie}}
  </option>
</ng-container>
like image 45
yurzui Avatar answered Oct 01 '22 11:10

yurzui