javascript - Angular - 我的 ngIf 仅隐藏一次输入标签
问题描述
*ngIf="currentIdea.oetSupportNeeded"
我有一个包含 2 个值的下拉列表 - 是和否,以及另一个可以自由书写的输入标签。我只想input-label
在用户在下拉列表中选择“是”时显示,并在选择“否”时隐藏它。
我的问题是以下代码只工作一次 - 当页面加载并选择“否”时,输入标签被隐藏,但是当您选择“是”然后再次选择“否”时,标签显示并且不会消失了。我希望它根据用户的选择打开/关闭
我尝试使用ngShow
, ngHide
,[disabled]
等。没有任何帮助
<div class="select-wrapper" [ngClass]="{'select-wrapper-blocked': isNotAdmin()}">
<select class="input-control" [(ngModel)]="booleanVariable">
<option value="false">No</option>
<option value="true">Yes</option>
</select>
</div>
</div>
<div class="col form-input" [ngClass]="{'form-input-blocked': isNotAdmin()}">
<p class="input-label">
Some text
</p>
<input *ngIf="booleanVariable" class="input-control" [(ngModel)]="stringVariable" />
</div>
解决方案
According to the code you shared, the value of your select menu is bound to the booleanVariable
property of your component.
Your *ngIf
queries another property, so the condition is wrong. You should be checking the booleanVariable
in the condition.
推荐阅读
- python - python replace 和 sub 不适用于 unicode 字符 u"\u0092"
- recaptcha - reCAPTCHA V2 不适用于 www.recaptcha.net
- c++ - 在 C++ 中计算矩阵的行列式而不创建子矩阵
- ios - 通过 MessageUI 在应用中发送短信
- c# - 禁用和启用反向绑定
- python - 在多索引中移动时间以合并
- entity-framework - 实体框架核心嵌套事务或在 saveChanges() 中更新 DbContext
- c# - 为什么要将现有的本地 IIS 网站添加到 Visual Studio 解决方案?
- java - 如何在 groovy 中使用整数除法运算符“/”?
- r - Shiny/shinydashboard:输出元素/值框的动态数量