0

I have a ng-if, I have a ng-for that shows me all the products I have, and I want to do in my ng if a validation that only shows when the array is empty or does not exist, this Is to display a message that products are not found on the page, Thank you! ;)

I try with "!ProductsCar" , but it does not work.

Code :

<ion-list *ngFor="let productsCar of productsCar">
    <ion-item-sliding>
  <ion-item class="item-prod">
    <ion-thumbnail item-start>
         <img  src="https://speedomart.000webhostapp.com/SPEEDOMART/{{productsCar.imagen}}">
    </ion-thumbnail>
    <div class="info-prod">
    <h2><b>{{productsCar.nombre}}</b></h2>
    <p>Codigo de barra : {{productsCar.codigo}}</p>
    <ion-icon name="md-pricetag"></ion-icon><b> $ {{productsCar.precio}}</b>
    </div>
 </ion-item>

      <ion-item-options side="right">
                         <button ion-button color="danger" (click)="borrarCar(productsCar)">
                               Borrar
                         </button>
      </ion-item-options>

    </ion-item-sliding>
    <div *ngIf="!productsCar">No tiene productos en su carro...</div>
</ion-list>

2 Answers 2

1

If you initialise productsCar with an empty array you can check its length:

TS:

productsCar: any = [];

HTML:

<div *ngIf="productsCar.length == 0">No tiene productos en su carro...</div>
Sign up to request clarification or add additional context in comments.

1 Comment

You can also use <div *ngIf="!productsCar.length ">...</div>
0

I actually came here to know how to do it... Tried the Andreas Grassmann solution and didn't work... try the original post and worked!

*ngIf="!vMyArray"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.