Search code examples
angularhidden

How to hide HTML template if a variable value is undedfined/null?


I have used ngFor to display my data. And i want to hide a div if variable value from ngFor is empty/undefined. My code is below. Can anybody help.

<li *ngFor="let parcel of dataSource;">

   <span hidden="parcel.ID==''">{{parcel.refrence }}</span>
</li>

Solution

  • Use *ngIf since your parcelID is undefined your condition should be *ngIf="parcel.ID"

    <li *ngFor="let parcel of dataSource;">
       <span *ngIf="parcel.ID">{{parcel.refrence }}</span>
    </li>