首页 > 解决方案 > 如何在特定条件下隐藏点击(Angular 4+)?

问题描述

我有一个点击按钮,假设在一定数量的输入后隐藏。我希望它在达到限制后隐藏,但目前它只会在再次单击时隐藏。这是一个糟糕的用户体验。

private isAddUserVisible = true;

public limitedAmount() {
    this.isAddUserVisible =
      this.userL.length + this.service.getTotalLength() < this.userService.getTotalValue();
    if (this.isAddUserVisible) {
      this.userL.push(this.create());
    }
  }
<div class="add-icon-button medium-3 columns" *ngIf="this.isAddUserVisible" (click)="limitedAmount()">

标签: htmlangular

解决方案


当然,我们没有全貌,但尝试手动调用更改检测。

注入constructor(private ref: ChangeDetectorRef)

然后调用:this.ref.detectChanges();where apppropiate

在此处 阅读有关它 的更多信息


推荐阅读