简体   繁体   English

如何检查角度 ngif 中的 2 个条件

[英]How to check 2 conditions in angular ngif

I am little stuck trying to get this *ngIf to work correctly.我很难让这个 *ngIf 正常工作。 What I am trying to do is show the div if it is empty only if the user viewing is owner.我要做的是仅当查看的用户是所有者时才显示 div 是否为空。 If the user is a guest, and the div is empty, it should not be shown.如果用户是客人,并且 div 为空,则不应显示。 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.如果用户是所有者并且 div 为空,这将显示 div。 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.我只是不确定如果用户是客人并且 div 为空,如何添加将隐藏它的子句。

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.但如果可能的话,我真的很想在 HTML 中做到这一点。 I am not sure if it even can be done.我不确定它是否可以做到。

Thank you for any help if possible you could give.如果可能的话,谢谢你的帮助。

它的逻辑:如果 div 不为空或用户是所有者,则显示 div:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM