Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to check 2 conditions in angular ngif

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<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.

>Solution :

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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading