NgIf and zero: Why is the template not being rendered?

Discussão em 'Angular' iniciado por Miguel Moura, Novembro 21, 2024.

  1. Miguel Moura

    Miguel Moura Guest

    I have the following observable on and Angular component:

    count$: Observable<number>;

    this.count$ = this.getCount();


    By using the following I get the value 0 (Zero);

    this.count$.subscribe(x => console.log(x));


    On the template I have:

    <a routerLink="/dash" *ngIf="(count$ | async)">
    <ng-container *ngIf="count$ | async as count">
    Count: {{count}}
    </ng-container>
    </a>


    If count$ is 1 I get Count: 1 but if count$ is 0 the content Count: 0 is not even rendered.

    Any idea why?

    Continue reading...

Compartilhe esta Página