0

I am very much upset trying with unsuccessful result.

There is an object array where inside the object there is/are a booking id/ids. Booking Id is an array inside the object. Booking Id hold 1 or more no. of booking id. I want to hide the booking id if there is only 1 booking id else I would like to display them.

How ever my code display all even if it is 1 or more.

    getBookingIds(){
  var myResult = this.customers;
    for(var i=0; i<myResult.length; i++){
      for(var j=0; j<myResult[i].bookingIds.length; j++){
        if(myResult[i].bookingIds.length > 2) {
          this.bookingId = true
        } else {
          this.bookingId = false;
        }
      }
  }
}

HTML

            <span class="bkidwrap" >
            <span class="bkids" *ngFor="let myBookingId of customer.bookingIds">
                <span class="bkid" *ngIf="bookingId">{{myBookingId}}</span>
            </span>
        </span>

enter image description here

1 Answer 1

1

You should be using hidden property binding by comparing the lengthas below

<span class="bkidwrap" >
      <span class="bkids" *ngFor="let myBookingId of customer.bookingIds" 
                  [hidden]="customer.bookingIds.length === 1">
           <span class="bkid" >{{myBookingId}}</span>
      </span>
 </span>
Sign up to request clarification or add additional context in comments.

2 Comments

I am continuously looking at your code. It seems very helpful. Waiting to see the result.
Its finally working brother. Thank you. I just want to cry in peace.

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.