Reputation: 283
Hi I've an *ngIf
condition where I'm checking for negation using ||
(or) operator but along with the ||
, I also need to check for &&
condition.
Basically I'm checking if activeIndex
is not 0
or 2
. 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
<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{}
.
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>
Upvotes: 0
Views: 2747
Reputation: 45
*ngIf="condition1 && condition2 && condition3"
You can use this to check for multiple 'AND' conditions, and in your case, you can use this:
*ngIf="(activeIndex !== 0 || (obj | json) !== '{}') && activeIndex !== 2"
Upvotes: 1
Reputation: 316
You can try this using KeyValuePipe also as shown below.
<ng-container *ngIf="(activeIndex === 0 && !(obj | keyvalue)?.length) || activeIndex === 2); else otherSteppers"></ng-container>
Upvotes: 0
Reputation: 1547
check this out
<ng-container *ngIf="(activeIndex !== 0 && (obj | json) == '{}') || activeIndex !== 2; else otherSteppers"></ng-container>
Upvotes: 2