Only render my widget if it is not empty with *ngIf

Asked

Viewed 532 times

0

I have the following variable:

listAtributos: any[] = [];

In my template I want to check if it is empty, if it is, do not show the content, if there is something inside it, show the contents of the div.

I tried something like:

<div *ngIf="listAtributos != null"

In this condition the div is rendered, even if it is in its initial state (listAtributos: any[] = [].

At some point in my code that list is copulated, when that happens, I want that div to be shown. However, it is being shown with this condition != null.

Am I applying the condition incorrectly? Is there something I haven’t noticed yet? Thank you very much.

1 answer

1


Try it this way:

<div *ngIf="listAtributos.length > 0">
//Código
</div>

or

<div *ngIf="listAtributos.length">
//Código
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.