代码之家  ›  专栏  ›  技术社区  ›  Roxy'Pro

如果列表/数组不为空,如何禁用角度按钮?

  •  0
  • Roxy'Pro  · 技术社区  · 6 年前

    在我的组件中,我从我的服务中获取数据:

    ngOnInit() {
      this._sharedService.
        getReceiptItem().takeUntil(this.ngUnsubscribe).
        subscribe(products => this.receiptItems = products);
    }
    

    如果我的数组 this.receiptItems 有什么东西吗?

    我试过这样的方法:

     <div class="top-left">
        <button [disabled]="receiptItems.count>0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>
     </div>
    

    但不经意间,这不是一个解决办法。

    谢谢

    4 回复  |  直到 6 年前
        1
  •  0
  •   Sajeetharan    6 年前

    Array.length

       <button [disabled]="receiptItems.length>0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>
    
        2
  •  1
  •   Krishna Rathore    6 年前

    length

    receiptItems:Array<any>;
    ngOnInit() {
      this._sharedService.
        getReceiptItem().takeUntil(this.ngUnsubscribe).
        subscribe(products => this.receiptItems = products);
    }
    

    <div class="top-left">
        <button [disabled]="receiptItems.length > 0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>
     </div>
    
        3
  •  1
  •   Super User    6 年前

    <div class="top-left">
        <button [disabled]="receiptItems && receiptItems.length>0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>
     </div>
    
        4
  •  1
  •   Roopesh Kumar Ramesh    6 年前
    <button *ngIf="receiptItems!=undefined" [disabled]="receiptItems.length>0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>