Reputation: 4270
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?
Upvotes: 42
Views: 78111
Reputation: 657376
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
Upvotes: 124