htmlangulartypescriptcontrol-flowangular-control-flow

*ngIf is not hiding the div in Angular 17


I'm trying to show a div if the conditions for *ngIf are met. I'm just not able to get it done. I have been trying this for hours.

<div *ngIf="item.billingItem=='Staff'">This is NOT showing. I don't know why</div>

However, the same condition is working:

<div>{{item.billingItem=='Staff'?'This is working':''}}</div>

What am I doing wrong? I feel like it's a silly mistake.


Solution

  • Since you are using angular17 go for @if no imports needed

    @if (item.billingItem=='Staff') {
        <div>This is NOT showing. I don't know why</div>
    }
    

    We also have @if and @else

    @if (item.billingItem=='Staff') {
        <div>This is NOT showing. I don't know why</div>
    } @else {
        <div>This is showing. I don't know why</div>
    }
    

    Angular control flow tutorial