Search code examples
angular2-directivesngforangular-ng-if

Excluding a value from ngFor


I have a dropdown that is populated with an *ngFor that iterates over a list of users. I want to exclude the current user from the list. Creating a whole pipe seems overkill. Is there a simple way to do this since Angular2 won't let me have both an *ngFor and an *ngIf on the same element?


Solution

  • Use *ngFor for the parent div and then for the child div use *ngIf to check whether it is a current user.

    `<div *ngFor=“ let user of users”><div *ngIF= “user != currentUser”>user</div></div>`