在我的组件中,我从我的服务获取数据:
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/