我试图通过模板驱动但不工作来验证角度2中的单选按钮。我在谷歌搜索也没有人正确回答。任何天才都可以回答这个问题?
https://stackblitz.com/edit/angular-zpyekb?file=src/app/app.component.html
app.component.html
<form #f="ngForm">
<div *ngFor="let option of options">
<div class="radio">
<input type="radio"
name="radio"
id="radio-{{option.id}}"
[(ngModel)]="value"
[value]="option.value"/>
<label for="radio-{{option.id}}">{{option.id}}
</label>
</div>
</div>
<div *ngIf="f.submitted">Please select</div>
<button>Submit</button>
</form>
<div *ngFor="let option of options">
<div class="radio">
<input type="radio"
name="radio"
id="radio-{{option.id}}"
[(ngModel)]="value"
[value]="option.value"
required
/>
<label for="radio-{{option.id}}">{{option.id}}
</label>
</div>
</div>
<div *ngIf="f.submitted && !f.valid">Please select</div>
May be you are looking for the above validation. If not can you please help to know what exactly you are looking for ?