html - 如何在特定条件下隐藏点击(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()">
解决方案
当然,我们没有全貌,但尝试手动调用更改检测。
注入constructor(private ref: ChangeDetectorRef)
然后调用:this.ref.detectChanges();
where apppropiate
在此处 阅读有关它 的更多信息
推荐阅读
- reactjs - TypeError:无法读取是的未定义的属性“对象”
- javascript - jQuery 使用许多多选字段进行验证(使用 Django)
- python - NaN 在 scikit-learn 的 OneHotEncoder 中给出 ValueError
- c# - 具有不同类型路由值的 Web Api 中的路由
- r - 如何在 R 中制作一组累积递增的整数?
- c - 递归函数内循环的时间复杂度
- c++ - C++ 中的时序逻辑错误(使用 std::chrono)
- r - 计算 r 中簇内的平均值
- javascript - 除了计算之外的任何其他方式来存储 Vue 路由参数,这样引用就不能被修改
- c# - 如何在 .NET MVC 网站的 URL 上添加 .xml?