Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/444.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果列表/数组不为空,如何禁用Angular中的按钮?_Javascript_Html_Angular_Css Selectors_Angular Services - Fatal编程技术网

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>