Radio button for boolean property

家住魔仙堡 提交于 2019-12-09 07:36:25

问题


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"/>

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.

What am i doing wrong?
Does anyone have a working "angular2-boolean-radio-input" snippet?


回答1:


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">

see also design doc for the new forms module



来源:https://stackoverflow.com/questions/38097472/radio-button-for-boolean-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!