*ngIf is adding elements instead of replaceing them

Discussão em 'Angular' iniciado por Abhijeet Chakraborty, Maio 3, 2025.

  1. My Code

    <i *ngIf="!isFollowing" class="far fa-bell"></i>
    <i *ngIf="isFollowing" class="fas fa-bell"></i>


    Type of isFollowing is Boolean

    Whenever I'm changing it to true or false it's showing the new element according to the expression but it is not removing the previous element but adding a new element to the DOM. As a result, multiple icons are visible like in the image.

    Multiple Icons being Added

    I believe change detection is detecting the change and adding a new DOM element but it's not updating the previous DOM Element.

    Continue reading...

Compartilhe esta Página