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?
Radio Button do not work for bool value.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With