user11767946
user11767946

Reputation:

How to make a click hide after certain condition (Angular 4+)?

I have a click button that is suppose to hide after certain amount of inputs. I would like it to hide once it reaches a limit, but currently what is doing that it would only hide when it's clicked again. Which is a bad user experience.

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()">

Upvotes: 0

Views: 42

Answers (1)

Wilson
Wilson

Reputation: 608

Of course, we don't have the whole picture but try manually calling change detection.

Inject constructor(private ref: ChangeDetectorRef)

and then call: this.ref.detectChanges(); where appropiate

Read more about it here

Upvotes: 1

Related Questions