Javascript 如果列表/数组不为空,如何禁用Angular中的按钮?
在我的组件中,我从我的服务中获取数据:Javascript 如果列表/数组不为空,如何禁用Angular中的按钮?,javascript,html,angular,css-selectors,angular-services,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">
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>
但显然,这不是一个解决方案
谢谢您可以尝试使用
长度
组件技术
receiptItems:数组;
恩戈尼尼特(){
这是共享服务。
getReceiptItem().takeUntil(this.ngUnsubscribe)。
订阅(products=>this.receiptItems=products);
}
component.html
您可以尝试使用
长度
组件技术
receiptItems:数组;
恩戈尼尼特(){
这是共享服务。
getReceiptItem().takeUntil(this.ngUnsubscribe)。
订阅(products=>this.receiptItems=products);
}
component.html
您需要在javascript中使用
<button [disabled]="receiptItems.length>0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>
您需要在javascript中使用
<button [disabled]="receiptItems.length>0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>
使用以下内容更新您的代码:
<div class="top-left">
<button [disabled]="receiptItems && receiptItems.length>0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>
</div>
使用以下内容更新您的代码:
<div class="top-left">
<button [disabled]="receiptItems && receiptItems.length>0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>
</div>
执行此操作[disabled]=“receiptItems?”lengthYes。非常感谢您的帮助执行此操作[disabled]=“receiptItems?”lengthYes。非常感谢你的帮助
<button *ngIf="receiptItems!=undefined" [disabled]="receiptItems.length>0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>