使用旧的表单,我可以设置选中单选按钮如下:
<div class="radio" *ngFor="let transport of transports">
<label>
<input type="radio" name="transport" [ngModel]="{checked: transport.id == selectedTransport.id}" (change)="onTransportChange(transport)"> {{ transport.name }}
</label>
</div>使用新的角形式,我无法用[ngModel]="{checked:''}"实现这一点,但我可以使用[checked],然后我尝试这样做:
<input type="radio" name="transport" [checked]="transport.id == selectedTransport.id"> {{ transport.name }}这是可行的,但是如果我设置了[ngModel],就不再检查了:
<input type="radio" name="transport" [checked]="transport.id == selectedTransport.id" [ngModel]="transport" (change)="onTransportChange(transport)"> {{ transport.name }}编辑:
旧形式的柱塞:http://plnkr.co/edit/zu4j9MpALIgCT9JHuIPz?p=preview
具有新表单的柱塞:http://plnkr.co/edit/cWCp5d122h3wvSRa8AYQ?p=preview
有人能帮我吗?谢谢!
发布于 2017-10-09 09:08:00
尝试指定值属性。请不要忘记,在单选按钮的情况下,Model不应该包含布尔值,而是应该包含无线电特定的值,例如:
Beef Lamb 鱼类
在这种情况下,您不需要选中属性。
https://stackoverflow.com/questions/38210266
复制相似问题