【发布时间】:2019-11-18 23:54:00
【问题描述】:
我对 Angular 中的 *ngIf 有一些问题。 如何再次隐藏我的内容?
在我在 Stackblitz 的示例中,我想在两个单选按钮未激活后再次隐藏我的内容。
当我单击“2”和“在家”时,会显示我的输出。但我希望它再次消失,例如,如果我说“在健身房”。
https://stackblitz.com/edit/angular-hcmstg
这里我给出了 ngModel
<label class="radio-inline"><input [(ngModel)]="split2" type="radio" name="radio1" value="two">2</label>
<label class="radio-inline"><input [(ngModel)]="split3" type="radio" name="radio1" value="three">3</label>
<label class="radio-inline"><input [(ngModel)]="split4" type="radio" name="radio1" value="four">4</label>
<label class="radio-inline"><input [(ngModel)]="home1" type="radio" name="radio2" value="home">at home</label>
<label class="radio-inline"><input [(ngModel)]="gym1" type="radio" name="radio2" value="gym">in the gym</label>
在这里我使用 * ngIf
<tr>
<th scope="row">1</th>
<td *ngIf="split2 && home1">{{home[0][0][1]}}</td>
<td *ngIf="split2 && home1">{{home[0][0][0]}}</td>
<td *ngIf="split2 && home1">{{home[0][1][0]}}</td>
</tr>
但如果我单击另一个单选按钮,它们不会隐藏。 输出永远保留
【问题讨论】:
标签: angular show-hide angular-ng-if