javascript - 如果列表/数组不为空,如何禁用 Angular 中的按钮?

标签 javascript html angular css-selectors angular-services

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

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>

但显然这不是一个解决方案..

谢谢

最佳答案

您需要Array.length在 JavaScript 中

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

关于javascript - 如果列表/数组不为空,如何禁用 Angular 中的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51186853/

相关文章:

javascript - 使用 Javascript 从远程 php 文件接收变量?

javascript - 如何在angularjs中将字符串解析为日期

html - 垂直对齐图像 + 底部文本

html - 在一个部门内对齐多个部门

javascript - 如何在 JavaScript 的 for 循环中分配 onclick ?

javascript - 使用 Angular.js 查找正在进行的 http get 请求的下载状态

angular - Ionic 3- 显示 base64 图像,清理不安全的 url 值 safevalue 必须使用 [property]=binding

Angular:观察两种状态但只执行一次

javascript - Angular 2 : ts - Supplied parameters do not match any signature of call target

javascript - 使用 javascript 访问 getElementById 的问题