我有一个带有模板的表单,用于创建新表单或加载和编辑现有表单。我已经将数据绑定应用到单选按钮字段集,使其根据来自数据库的数据进行切换。在这样做时,由于某种原因,*ngIf用于切换其他div的可见性不再工作。
之前(可见性切换工作):
<div class="col-xs-12 col-sm-12">
<fieldset>
<input type="radio" formControlName="specificPilot" value="1" [ngClass]="{'td-radio-error': displayMessage.specificPilot}" (check)="radioSetValidator(changeForm.get('generalQuestionsFG.specificPilot'),[changeForm.get('generalQuestionsFG.pilotTransits')])">Yes
<input type="radio" formControlName="specificPilot" value="0" [ngClass]="{'td-radio-error': displayMessage.specificPilot}" (check)="radioSetValidator(changeForm.get('generalQuestionsFG.specificPilot'),[changeForm.get('generalQuestionsFG.pilotTransits')])">No
{{this.changeForm.get('generalQuestionsFG.specificPilot').value}}
</fieldset>
</div>
<div class="col-xs-12 col-sm-12">
<textarea class="form-control" rows="2" formControlName="pilotTransits" style="width:100%" placeholder="Provide Transits for Pilot(s)"
*ngIf="changeForm.get('generalQuestionsFG.specificPilot').value==='1'"></textarea>
</div>
之后(数据绑定有效,但可见性切换无效):
<div class="col-xs-12 col-sm-12">
<fieldset>
<input type="radio" formControlName="specificPilot" [value]="1" [ngClass]="{'td-radio-error': displayMessage.specificPilot}" (check)="radioSetValidator(changeForm.get('generalQuestionsFG.specificPilot'),[changeForm.get('generalQuestionsFG.pilotTransits')])">Yes
<input type="radio" formControlName="specificPilot" [value]="0" [ngClass]="{'td-radio-error': displayMessage.specificPilot}" (check)="radioSetValidator(changeForm.get('generalQuestionsFG.specificPilot'),[changeForm.get('generalQuestionsFG.pilotTransits')])">No
{{this.changeForm.get('generalQuestionsFG.specificPilot').value}}
</fieldset>
</div>
<div class="col-xs-12 col-sm-12">
<textarea class="form-control" rows="2" formControlName="pilotTransits" style="width:100%" placeholder="Provide Transits for Pilot(s)"
*ngIf="changeForm.get('generalQuestionsFG.specificPilot').value==='1'"> </textarea>
</div>
有人能解释一下为什么检查单选按钮控件值的ngIf不再工作了吗?我在中添加了stubcode,以检查值是否正确更改。