admin管理员组文章数量:1355710
In my ponent I'm getting data from my service:
ngOnInit() {
this._sharedService.
getReceiptItem().takeUntil(this.ngUnsubscribe).
subscribe(products => this.receiptItems = products);
}
So how can I disable a button if my array this.receiptItems
has any items?
I've tried something like this:
<div class="top-left">
<button [disabled]="receiptItems.count>0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>
</div>
But obliviously that is not a solution..
Thanks
In my ponent I'm getting data from my service:
ngOnInit() {
this._sharedService.
getReceiptItem().takeUntil(this.ngUnsubscribe).
subscribe(products => this.receiptItems = products);
}
So how can I disable a button if my array this.receiptItems
has any items?
I've tried something like this:
<div class="top-left">
<button [disabled]="receiptItems.count>0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>
</div>
But obliviously that is not a solution..
Thanks
Share Improve this question asked Jul 5, 2018 at 8:40 Roxy'ProRoxy'Pro 4,46410 gold badges49 silver badges120 bronze badges4 Answers
Reset to default 4You need Array.length
in javascript
<button [disabled]="receiptItems.length>0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>
Update your code with following:
<div class="top-left">
<button [disabled]="receiptItems && receiptItems.length>0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>
</div>
You can try with length
ponent.ts
receiptItems:Array<any>;
ngOnInit() {
this._sharedService.
getReceiptItem().takeUntil(this.ngUnsubscribe).
subscribe(products => this.receiptItems = products);
}
ponent.html
<div class="top-left">
<button [disabled]="receiptItems.length > 0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>
</div>
<button *ngIf="receiptItems!=undefined" [disabled]="receiptItems.length>0" type="button" [routerLink]="['/administration']"><i class="fas fa-bars fa-fw"></i></button>
本文标签: javascriptHow to disable button in Angular if listarray is not emptyStack Overflow
版权声明:本文标题:javascript - How to disable button in Angular if listarray is not empty? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743987596a2571551.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论