简体   繁体   English

Angular *ngIf 带有“AND”和“OR”运算符的多个条件

[英]Angular *ngIf multiple condition with 'AND' and 'OR' operator

Hi I've an *ngIf condition where I'm checking for negation using ||嗨,我有一个*ngIf条件,我正在使用||检查否定(or) operator but along with the || (或)运算符,但与||一起, I also need to check for && condition. ,我还需要检查&&条件。

Basically I'm checking if activeIndex is not 0 or 2 .基本上我正在检查activeIndex是否不是02 But now I also need to check for and condition like activeIndex is not 0 AND obj (object) is empty{} OR activeIndex is not 2但现在我还需要检查和条件,比如activeIndex不是0 AND obj (object) is empty{} OR activeIndex is not 2

<div class="lmn-my-0 lmn-py-0">
<ng-container *ngIf="!(activeIndex === 0 || activeIndex === 2); else otherSteppers">
 // if condition some code
</ng-container>
<ng-template #otherSteppers>
// else some code
</ng-template>
</div>

How can I add condition activeIndex is not 0 AND obj (object) is empty{} .如何添加条件activeIndex is not 0 AND obj (object) is empty{}

I tried below code but it didn't work.我尝试了下面的代码,但没有用。 Can anyone suggest what I'm doing wrong, if no how can we achieve such condition任何人都可以建议我做错了什么,如果没有我们怎么能达到这样的条件

<ng-container *ngIf="!(activeIndex === 0 && (obj | json) == '{}' || activeIndex === 2); else otherSteppers"></ng-container>

check this out看一下这个

<ng-container *ngIf="(activeIndex !== 0 && (obj | json) == '{}') || activeIndex !== 2; else otherSteppers"></ng-container>

You can try this using KeyValuePipe also as shown below.您也可以使用KeyValuePipe尝试此操作,如下所示。

<ng-container *ngIf="(activeIndex === 0 && !(obj | keyvalue)?.length) || activeIndex === 2); else otherSteppers"></ng-container>
*ngIf="condition1 && condition2 && condition3"

You can use this to check for multiple 'AND' conditions, and in your case, you can use this:您可以使用它来检查多个“AND”条件,在您的情况下,您可以使用它:

*ngIf="(activeIndex !== 0 || (obj | json) !== '{}') && activeIndex !== 2"

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

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