我想先默认选中一个单选按钮。之后,当我回来时,我想检查从数据库Angular 2中选择的值的单选按钮

时间:2017-05-18 05:38:52

标签: asp.net asp.net-mvc angular2-forms

如何首先检查默认单选按钮。单击上一个按钮,然后选中上一个选定值单选按钮。

<input type="radio" name="Answer" [(ngModel)]="Answer" [value]="Test[i].ans1" (change)="selected(Test[i].ans1)"  formControlName="Answer"> :{{Test[i].ans1}}<br />
<input type="radio" name="Answer" [(ngModel)]="Answer" [value]="Test[i].ans2" (change)="selected(Test[i].ans2)"  formControlName="Answer"> :{{Test[i].ans2}}<br />
<input type="radio" name="Answer" [(ngModel)]="Answer" [value]="Test[i].ans3" (change)="selected(Test[i].ans3)" formControlName="Answer"> :{{Test[i].ans3}} <br />
<input type="radio" name="Answer" [(ngModel)]="Answer" [value]="Test[i].ans4" (change)="selected(Test[i].ans4)" formControlName="Answer"> :{{Test[i].ans4}}<br />
</div>
<button (click)="Prevoius($event)" class="btn btn-primary">Previous</button>
<button type="button" [disabled]="radioTest.controls['Answer'].invalid" (click)="Next($event)" class="btn btn-primary">Next</button> 
</form>

1 个答案:

答案 0 :(得分:1)

你可以这样做

<input type="radio" name="Answer" [(ngModel)]="Answer" [value]="Test[i].ans1" (change)="selected(Test[i].ans1)" [checked] =“!Answer”  formControlName="Answer"> :{{Test[i].ans1}}<br />

使用[checked]可以勾选复选框