Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Radio button for boolean property

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 not 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 doesn't seem to have impact on the HTML radio-input.

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

like image 802
Philipp Avatar asked Jun 29 '16 10:06

Philipp


People also ask

Can radio button have Boolean value?

Radio Button do not work for bool value.

Which property is need to group radio button?

Use the GroupName property to specify a grouping of radio buttons to create a mutually exclusive set of controls. You can use the GroupName property when only one selection is possible from a list of available options. When this property is set, only one RadioButton in the specified group can be selected at a time.


1 Answers

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

like image 193
Günter Zöchbauer Avatar answered Oct 06 '22 13:10

Günter Zöchbauer