Home > Net >  How to check 2 conditions in angular ngif
How to check 2 conditions in angular ngif

Time:05-14

I am little stuck trying to get this *ngIf to work correctly. What I am trying to do is show the div if it is empty only if the user viewing is owner. If the user is a guest, and the div is empty, it should not be shown. here is what I have:

<div *ngIf="(tray.flyers.length === 0) && (isOwner === true)"></div>

That will show the div if the user is owner and the div is empty. I'm just not sure how to add the clause that will hide it if the user is a guest and the div is empty.

I have trying to figure this out for a couple hours and can't see to see how it would work.I know I can get this to work if I do everything in the component and just do:

<div[hidden]="isTrayEmpty"></div>

but I was really wanted to do this in the HTML if possible. I am not sure if it even can be done.

Thank you for any help if possible you could give.

CodePudding user response:

It's logic: Show the div if its NOT empty OR the user is the owner:

<div *ngIf="(tray.flyers.length > 0) || (isOwner === true)"></div>
  • Related