-1

i want to loop the user list with condition

<li *ngFor="let user of users" *ngIf="user.age>25"> {{user.name}} </li>

i know this is wrong. but,i want to use come like this. is there any possible way to this?

Ragulan
  • 1,677
  • 17
  • 24

2 Answers2

2

You can use ng-container as follows

<ng-container *ngFor="let user of users" >
   <li *ngIf="user.age>25">
      {{user.name}}
   </li> 
</ng-container>
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • it working well, but id creating unwanted dom like it is not a problem but is there any way to stop that also? – Ragulan Sep 17 '19 at 11:35
0

You can't apply more than one structural directive to the same element. Just use ng-container:

<ng-container *ngFor="let user of users">
<li  *ngIf="user.age>25"> {{user.name}} </li>
<ng-container>

ng-container is

a grouping element that doesn't interfere with styles or layout because Angular doesn't put it in the DOM.

Martino Bordin
  • 1,412
  • 1
  • 14
  • 29