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

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 this list is copulated, when this happens, I want this div to be displayed. However, it is being displayed with this condition! = Null.

Am I applying the condition incorrectly? Is there something I still did not realize? Many thanks.

    
asked by anonymous 08.11.2018 / 16:44

1 answer

1

Try this:

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

or

<div *ngIf="listAtributos.length">
//Código
</div>
    
08.11.2018 / 16:57