如果数组在angular2中大于1则隐藏

Hide if array is more than 1 in angular2

我很不高兴尝试失败的结果。

有一个对象数组,对象内部有 is/are 预订 id/ids。 Booking Id 是对象内的一个数组。预订编号保留 1 个或多个编号。预订编号。如果只有 1 个预订 ID,我想隐藏预订 ID,否则我想显示它们。

我的代码怎么显示全部,即使它是 1 个或更多。

    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>

您应该使用隐藏 属性 绑定,方法是比较下面的长度

<span class="bkidwrap" >
      <span class="bkids" *ngFor="let myBookingId of customer.bookingIds" 
                  [hidden]="customer.bookingIds.length === 1">
           <span class="bkid" >{{myBookingId}}</span>
      </span>
 </span>