布尔属性的单选按钮 [英] Radio button for boolean property
问题描述
我的对象document
中有一个简单的布尔属性valid
并需要将其绑定到无线电输入.
I have a simple boolean property valid
in my object document
and need to bind it to radio-inputs.
这是我到目前为止所拥有的:
This is what i have so far:
<input type="radio" name="valid" id="validTrue" (click)="document.valid = true" [checked]="document.valid"/>
<input type="radio" name="valid" id="validFalse" (click)="document.valid = false" [checked]="!document.valid"/>
至少可以在单击时设置该属性,但是单选输入不会显示其状态.在浏览器的开发人员控制台中查看时,我发现设置了属性ng-reflect-checked
,但似乎对html无线电输入没有影响.
At least setting the property on click works but its state is no displayed by the radio-inputs. Looking in the developer console of my browser i found out that a property ng-reflect-checked
is set but it doesnt seem to have impact on the html radio-input.
我做错了什么?
有人可以使用"angular2-boolean-radio-input"代码段吗?
What am i doing wrong?
Does anyone have a working "angular2-boolean-radio-input" snippet?
推荐答案
在新的表单模块中,这可能会做您想要的
In the new forms module this might do what you want
<input type="radio" name="food" [(ngModel)]="document.valid" [value]="true">
<input type="radio" name="food" [(ngModel)]="document.valid" [value]="false">
另请参见新表单模块的设计文档
这篇关于布尔属性的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!