【发布时间】:2017-10-31 11:19:01
【问题描述】:
我有一个包含输入的 for 循环,每个循环由五个单选值组成,其名称和模型是动态的。
我想将值 1 设置为默认值,我可以使用通常的 html "checked" 或 "checked = checked" 但它只能在没有 ngModel 的情况下工作,如果我使用的是 ngModel,我必须在组件类中对其进行初始化但是因为它是动态的,所以我无法先初始化它。
还有其他选择吗?还是我遗漏了什么??
<div class="scorecard-attribute" *ngFor="let attribute of opportunity.scorecard.scorecard_attributes">
<input type="radio" name="{{attribute.name}}" [value]=1 [(ngModel)]="newRating[attribute.id]" checked>
<input type="radio" name="{{attribute.name}}" [value]=2 [(ngModel)]="newRating[attribute.id]">
<input type="radio" name="{{attribute.name}}" [value]=3 [(ngModel)]="newRating[attribute.id]">
<input type="radio" name="{{attribute.name}}" [value]=4 [(ngModel)]="newRating[attribute.id]">
<input type="radio" name="{{attribute.name}}" [value]=5 [(ngModel)]="newRating[attribute.id]">
【问题讨论】:
标签: javascript html angular angular2-ngmodel